Memory leak with container controls

G

Guest

Hello,

I have a form with a button, the button opens another form using showdialog.
The second form contains a panel which contains a tabcontrol wich contains on
each of its tabs a bunch of labels. After closing the second form, I call
dispose and even ask for garbage collection, but even this way the memory is
not freed.

This is the code that opens the form:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim formu As New Form2
formu.ShowDialog()
formu.Dispose()
formu = Nothing
GC.Collect()
End Sub

I don't know if it's a known bug and if there's any solution to this
problem. I tried upgrading from compact framework 1 sp3 to 2.0, but it's
still the same.

Thanks a lot

Joaquín Raya
 
G

Guest

I added this code to the second form in a kinda desperate attempt to fix this:

Private Sub Form2_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
For Each c As Control In Me.Controls
Borrar(c)
Next
End Sub
Private Sub Borrar(ByVal c As Control)
For Each con As Control In c.Controls
Borrar(con)
con.Dispose()
Next
End Sub

But still no result. I still find the leak.
 
G

Ginny Caughey [MVP]

Joaquin,

What makes you think there is a problem? Does your app crash or anything
like that? You may just be seeing normal behavior of the garbage collector.
 
G

Guest

Well, yes. When you repeat this process a few hundred times, it starts asking
the user to close applications.
The problem was found by our client, who reported that if they used the
application for a long time without reseting they got the "close some apps"
messages.

I believe it's not the normal garbage collector behaviour not to free memory
from disposed objects after collecting.
 
G

Ginny Caughey [MVP]

Joaquin,

Ok the next thing to look for is any native objects you may not be disposing
of.
 
G

Guest

There are no native controls, I built a test project from scratch in order to
reproduce the problem keeping it as simple as I could.

Form1 has one button thal loads form2
Form2 has:

- a windows.forms.panel
- the windows.forms.panel contains a tabcontrol with 3 tabpages
- each tabpage contains a few windows.forms.label

There is nothing more in the whole project. If you want I can email you the
full source code or something.
 
G

Guest

Is this by chance CF 1.0 RTM? There was a bug that Form controls did not
get properly disposed in early versions, but I think it was fixed in SP1 or
SP2.

-Chris
 
G

Guest

Nope. It's both CF 1.0 SP3 and 2.0

Is this by chance CF 1.0 RTM? There was a bug that Form controls did not
get properly disposed in early versions, but I think it was fixed in SP1 or
SP2.

-Chris
 
G

Ginny Caughey [MVP]

Joaquin,

Sure email me the project. Just remove online from my email address.
 
G

Guest

Sent. I'm at my workplace now, and the mail system has been known to cause
general mischief with emailed projects, including but not limited to delete
zipped .vb files, so please mail me if you don't get the project right
 
G

Ginny Caughey [MVP]

Got it, thanks. I'm testing it now, but I imagine it will take quite a few
tries to break it.
 
G

Guest

You just need to run it check how much memory you have left before clicking
the button, then click it and close the modal form a few times, then check
memory again.
 
G

Ginny Caughey [MVP]

Joaquin,

I can see the memory usage increasing about .01 Mb each time I close the
modal form, but even after closing the app the memory used remains the same.
Since I only tried this a few dozen times, I can't say for sure that it
isn't normal garbage collection action at this point. BTW I tested using CF
2.0.
 
G

Guest

When I try this, after closing the app the memory gets freed.

I really hope it's not normal garbage collection. Users complain that my app
starts getting all the memory on the pocket pc after a long time without
closing.
 

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