help:nothing gets disposed

  • Thread starter Thread starter Barba
  • Start date Start date
B

Barba

I have checked my program with memory profiler and it turns out that nothing
gets disposed.
As child form is opened and closed, it remains in memory.
Is there a way to clear memory manually? (GC.Collect() and similar have no
effect)
 
Hi Barba,

You can't force GC to run when you want, and it doesn't run unless it
finds a reason to do so.
This may mean that objects may reside in memory even though you are
finished with them, until the memory usage reaches a certain limit.

You can try to use GC.Collect() to attempt to get it to run.

Happy coding!
Morten Wennevik [C# MVP]
 
This may mean that objects may reside in memory even though you are
finished with them, until the memory usage reaches a certain limit.

It grabs memory until there is no free memory to grab, then crahses (with
virtual memory disabled for testing)
You can try to use GC.Collect() to attempt to get it to run.

Does not do anything


It seems that garbage collector works fine as long as data is not displayed
on screen (5mb data array gets removed from memory, but if it was placed
into datagrid or rtbox, it will remain in memory).

This problem only occurs on child forms.

Also, this problem is not occuring on Win98SE (I use WinXP Pro)
 
That means you are still holding references to managed memory.
Just post a short but complete code sample that illustrates the problem.

Willy.
 
Just post a short but complete code sample that illustrates the problem.

below is one of functions in main form which display child form.
when child form is closed, it remains in memory

public static void showCForm(int arg)
{

try
{

CForm childForm=null;
foreach(Form f in Brazda.Startup.ActiveForm.MdiChildren)
{


if(f is CForm)
{
switch (arg)
{
case 122:
if (f.Text=="122") //brzi najam
childForm = (CForm) f;
break;
case 123:
if (f.Text=="123") //izmjena najma
childForm = (CForm) f;
break;
case 207:
if (f.Text=="207") //PC Blagajna (robno)
childForm = (CForm) f;
break;
case 422:
if (f.Text=="422") //brzi najam marina brod+gosti
childForm = (CForm) f;
break;
case 423:
if (f.Text=="423") //izmjena najma marina brod+gosti
childForm = (CForm) f;
break;
case 722:
if (f.Text=="722") //brzi najam
childForm = (CForm) f;
break;
case 723:
if (f.Text=="723") //izmjena najma
childForm = (CForm) f;
break;
case 807:
if (f.Text=="807") //POS
childForm = (CForm) f;
break;
}
}
}
if( childForm != null)
{ //it is already open, just show it
childForm.Show();
childForm.Focus();

}
else
{ //load form
childForm = new CForm(arg);
childForm.MdiParent = Brazda.Startup.ActiveForm;
childForm.Show();
childForm.Focus();
}
}
catch//(Exception exp)
{
//MessageBox.Show(exp.Message);
}
}
 
Barba said:
It grabs memory until there is no free memory to grab, then crahses (with
virtual memory disabled for testing)


Does not do anything


It seems that garbage collector works fine as long as data is not
displayed on screen (5mb data array gets removed from memory, but if it
was placed into datagrid or rtbox, it will remain in memory).

This problem only occurs on child forms.

Also, this problem is not occuring on Win98SE (I use WinXP Pro)

Add

gc.WaitForPendingFinalizers()

after

gc.Collect()
 
I asked for a short but complete sample, I don't see a Form.Close() call.

Willy.
 
Back
Top