Memory problem when opening forms?

G

Guest

Hi....I am trying to write a little program for windows mobile 5 with
vb2005...but I have got problems...when I open a new form and close it again
and then I repeat this procedure some time then my memory get full....I am
calling the forms like this:

Sub OpenOptions()
Dim options as new frmOptions

options.show()
End Sub

and in the optionsform I am closing the form like this:

Sub Exit()
me.close()
End Sub

Please help me....thank you....juvi
 
D

Daniel Moth

So you sent me a project direct. It is best to post to the newsgroup (or
post to the ng a URL to the zipped project) if your interface doesn't allow
attachments.

Anyway, your project has nothing more than a form opening another form
(which also has a button that really closes the form).

If you look at what I asked below, I said make available to the newsgroup a
solution that shows an OOM exception. In your comments of the single method
you sent me you say:
'When I open and close this form some times
'then the memory will be full. I do not get
'a OutOfMemoryException early because my RAM as big
'but I can see how the memory grows with a memoryinfo plugin

So at this point I have to direct you back to my original reply and
specifically the link again:
http://www.danielmoth.com/Blog/2005/01/memory-problems-faq.html

If you are not seeing an OOM the you don't necessarily have a problem. When
the GC kicks in, the memory will be reclaimed; that is how managed
environments work.

Cheers
Daniel
 
G

Guest

Sorry for my late answer to your message...thank you for your reply....I
tried it with the GetTotalMemory(false) method and I can see how the memory
consumption is growing to about 1MB (....my program is only 32kb big ) ...The
memory is released every time after 10seconds. I have got a timer on my form,
which works with an image (for an analog clock)....Is there a way now to tell
the system to release the memory earlier?
 
M

Markus Humm

juvi said:
Sorry for my late answer to your message...thank you for your reply....I
tried it with the GetTotalMemory(false) method and I can see how the memory
consumption is growing to about 1MB (....my program is only 32kb big ) ...The
memory is released every time after 10seconds. I have got a timer on my form,
which works with an image (for an analog clock)....Is there a way now to tell
the system to release the memory earlier?

Maybe with gc.collect
 
G

Guest

If you're not actually having problems, then don't worry about it. 1MB is
the GC Heap threshold, so growth to 1MB is not a surprise, nor will a GC
collect get it back. in fact manually calling GC collect will cause a perf
problem because the GC has to scan the heap for all reachable every time
it's called.

-Chris
 
G

Guest

Thank you for your reply. I have got to devices:
- Acer n311 (nothing installed - memory consumption without my program 34%
and with my program up to 45%...I guess because of the .net framaework in the
background)
- FS Pocket Loox 420 (many programs installed...when I start my program then
I get a OutofMemory Exception)

So it would be great to reduce the memory consumption...GC collect is one
way...ok...but if I have to clean up every second then I think it will slow
down...are there other ways to reduce it? thank you.....juvi
 
G

Guest

Calling GC.Collect will do nothing for you. If you're getting OOMs, then you
need to try to reduce the pressure your app puts on the system by reducing
object size, the number of live objects requires at any given time, etc.

-Chris
 
G

Guest

Could I maybe send you a little code sample of my program? I do not really
find my mistake....I dispose everything immediately after using it, but it
does not help...juvi
 
G

Guest

Post it here. I rarely accept submissions directly as they don't benefit
the community.

-Chris
 
G

Guest

Thank you for all your help, but it seems to work now: I use this code to
free up memory:

System.GC.Collect()
System.GC.WaitForPendingFinalizers()
System.GC.Collect()

thank you again

juvi
 
G

Guest

If that fixes it, then my guess is you have other problems. If the system
is low on memory, then an OOM will cause an automatic GC. But by all means,
put that in there - a walk through the heap not once but twice looking for
reachable objects ought to be fun for the user.

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top