First try installing the latest service-pack on your device - SP3 and see if
this helps. While it's quite normal for memory not the be released
immediately when objects are finished with as the garbage collector should
only kick in under certain curcumstances (detailed in this post
http://blogs.msdn.com/scottholden/archive/2004/12/28/339733.aspx), if you
are reaching a point where free memory is exhaustedd this would indicate a
problem though.
What sort of operations are carried out on the forms, do you do a lot of
custom drawing? load data? are you using P/Invokes to work with native
resources such as graphics or io? does your app hold references to the forms
anywhere which would prevent them from being garbage collected?
Peter

Signature
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org
> Hi,
>
[quoted text clipped - 4 lines]
>
> Paul
Sidebp - 27 May 2005 11:15 GMT
Hi Peter,
Thanks for yout input once again and thanks for your work on the
openNetCF!
I will try installing SP3 and see what happens - my only thought is
that its such a common operation that I'm probably doing something
wrong? Cant imagine there would be a memory leak when opening/closing
forms? One thing I have noticed is that memory usage increases when i
show a hidden textbox - this happens a lot on some of my pages and the
memory never seems to be recovered.
What sort of operations are carried out on the forms, do you do a lot
of
custom drawing?
Nope - predominantly I use a streamwriter which i close and dispose of.
The only other operation on one of the forms is barcode scanning -
which led me to be suspect of the objects provided for this purpose.
However the same problem appears on all of my forms.
are you using P/Invokes to work with native
resources such as graphics or io?
I use getPowerStatusEx on each form (I have seen a native exception
occur) which I believe may be as a result of this??
does your app hold references to the forms
anywhere which would prevent them from being garbage collected?
not that i know of. Predominantly I do the following:
dim x as new Formname
x.show
then when closing...I call a routine which sets all objects to nothing
and then call
me.close
from my understanding, me.close will also call dispose (this will also
dispose of any child objects on the form?)
Thanks again - anyones input is truely valued!!
Sidebp - 27 May 2005 11:32 GMT
Ok so it doesnt get simpler than this - I tried the following code and
profiled memory usage - every time i opened the form memory usage
dropped, even after a course of time/hundreds of forms opened - the
memory was not recovered. I even did a system.gc.collect()
On FORM1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Form2
x.ShowDialog()
x.Dispose()
End Sub
On FORM2
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Dispose()
End Sub
Daniel Moth - 27 May 2005 21:14 GMT
So you are running this on SP3, Form2 has no other code apart from the
button_click and nothing else happens in the application, right? Change the
Me.Dispose to Me.Close and if you get an OOM exception, post the sample
project for us to try (also tell us what device you are running on).
For more on memory problems, check this out:
http://www.danielmoth.com/Blog/2005/01/memory-problems-faq.html
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
> Ok so it doesnt get simpler than this - I tried the following code and
> profiled memory usage - every time i opened the form memory usage
[quoted text clipped - 16 lines]
> Me.Dispose()
> End Sub
Sidebp - 31 May 2005 09:00 GMT
Correct - Form2 only has the standard Windows Form generated code -
this is the only routine in the app. Will try the recommended change.
thanks