Serious memory trouble!!!

  • Thread starter Thread starter Sergio Silveira
  • Start date Start date
S

Sergio Silveira

Hi,

I have an application that keeps eating up memory
whatever I do inside it.

Ex: I open my Application, then, inside it, I open a form
wich fills a datagrid, etc... and when I close that form
the memory stays the same instead of going down.


I have tried everything, even the Garbage Collection
(GC.Collect) and nothing.


Thanks

Sergio Silveira
 
* "Sergio Silveira said:
I have an application that keeps eating up memory
whatever I do inside it.

Ex: I open my Application, then, inside it, I open a form
wich fills a datagrid, etc... and when I close that form
the memory stays the same instead of going down.


I have tried everything, even the Garbage Collection
(GC.Collect) and nothing.

Memory Profiler:

<http://www.gotdotnet.com/Community/...mpleGuid=3254325d-a4aa-4bb3-aa86-c72d5104ec74>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
Are you opening the form with ShowDialog()?
What version of the .NET framework and VS.NET are you using?

Can you post code that shows how you open and close the form? Be sure that
you are calling Dispose().

-Eric
 
--------------------------------------------------------
To Open:
--------------------------------------------------------

Private Sub brSearch_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btSearch.Click

Dim NewSearchForm As New frmSearch
NewSearchForm .MdiParent = Me.MdiParent
GetMDIChildsWinState(Me.MdiParent, NewSearchForm )
NewSearchForm .Show()

End Sub

--------------------------------------------------------
To Close:
--------------------------------------------------------

Private Sub frmExample_Closed(ByVal sender As
Object, ByVal e As System.EventArgs) Handles MyBase.Closed

'Just going nuts...

Dim Thing As Control

For Each Thing In Me.Controls
Try
Thing.Dispose()
Catch ex As Exception
End Try

Try
Thing = Nothing
Catch ex As Exception
End Try

Next


'Original code, the above code is just for testing
purposes. but it doesn't work
GC.Collect()
GC.WaitForPendingFinalizers()

End Sub
 
Are you using 1.0 or 1.1 of the Framework?

Put your Dispose code in the Dispose() method provided by the designer and
make sure it's being called by placing a break point in there.

There are documented and undocumented leaks in some of the Windows.Forms
classes, the idea is that you need to release as much memory as you can
because the Form may not be correctly Disposed. That means calling Dispose
on everything that supports it and setting ALL references to null. I've also
gone as far as to remove all event subcriptions from my controls. Make sure
you go inside some of the objects like PictureBox.

if(pictureBox1 != null)
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
pictureBox1.Dispose();
pictureBox1 = null;
}

Unfortunately, I haven't seen a good clean way to call Dispose on
everything. It's not pretty, but it makes a huge difference!

Here's some related links, it explains some of the documented leaks and how
to correct it.
http://www.automatedqa.com/techpapers/net_allocation_profiler.asp
http://www.scitech.se/memprofiler/
http://support.microsoft.com/default.aspx?scid=kb;en-us;817723

I played with the scitech profiler a bit. Their documentation (PDF) is also
helpful.

HTH;
Eric Cadwell
http://www.origincontrols.com
 
Back
Top