should I help Garbage Collector?

  • Thread starter Thread starter Piotrek Stachowicz
  • Start date Start date
P

Piotrek Stachowicz

Hi,
[Windows Forms]
I have a panel in which I create lots of controls (a few hundreds,
this.panel1.Controls.Add(...) ) , but they are there only for a short
while - when user pushes button I call clear panel, and populate it with
another (brand new) set of controls.
Currently, I leave the cleaning job to GC, and just don't care, but
perhaps I could help him somehow?

Piotrek
 
Hi,
[Windows Forms]
I have a panel in which I create lots of controls (a few hundreds,
this.panel1.Controls.Add(...) ) , but they are there only for a short
while - when user pushes button I call clear panel, and populate it with
another (brand new) set of controls.
Currently, I leave the cleaning job to GC, and just don't care, but
perhaps I could help him somehow?

Piotrek


You're much better off leaving it that way, probably. Make sure that you
unsubscribe from any events on the control's you're getting rid of, though.
 
No, sod it. The GC will love you - it will have a chance to execute its rarely-used-but-essential algorithms.
NEVER try to help the GC - it does a very complex job in a very elegant way - it is very sophisticated in its ways of not actually releasing memory if it's only going to be using it again in a short while, saving on a lot of processor time and memory allocation resources, giving it a 'managed memory pool', hence the term, managed. It is this sophisticated 'managed pooling' that gives .NET programs an advantage over raw C++ programs.
 

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

Back
Top