UserControl's and Dispose/GC.Collect question

  • Thread starter Thread starter james
  • Start date Start date
J

james

If I have a user control with some control on it like
a TextBox's and buttons does calling the default Dispose
on my user control cause those inner controls to also
be disposed ? Or must I do my own disposing for
all those too??

thanks,

JIM
 
Hi,

It is not clear how you call the dispose method here

if you need to dispose a specific control such as a button then you can call
the button.Dispose() method or else if you need the whole control colletion
to be clear then you can call the MyUserControl.Controls.Clear()

Nirosh.
 
Chanpika,

What I am saying is this, I have a Custom User Control,
that has many inner controls on it. When I want it to
go away entirely and free all its memory, my containing
Form does this,

SomeUserControl.Dispose();
SomeUserControl = null;
GC.Collect();

But, what I am finding is that no memory is being freed.
I know this because I have many of these controls, that
I create, display and destroy, and as I create them I can
see memory going up, but as I destroy them memory
does not go down. My application is gobbling up
over 250MB by itself, when I know for a fact that it only
requires about 60MB initially, but as time goes on, it keeps
growing until eventually the OS just kills it because it has
grabbed too much menory. So, I am guessing that each
UserControl is not releasing its inner controls. I thought
that since those were in the this.Controls() IList that they
would be auto handled by the base class's destroy.
So that was my question. Are inner controls auto freed
or not ???

thanks,

JIM
 
Back
Top