
Tip : VB.NET Form Won't Close on Me.Close + User Controls
Calling GC.Collect releases it from memory at that instant (req'd for my app
due to multiple instances of forms which take about 10MB each, mostly GDI).
If I don't call it, the garbage collector will hold it in memory, maxing it
out, only to release it upto 20 minutes later all at once or when your CPU
is idle. This 'batch' clearing of memory spikes the CPU as well. To avoid
all this, i call GC.Collect on form close.
I clear my controls from my form in the same way objects are disposed. Each
control has a real-time connection streaming data from a websvc, so it's
more of a precautionary measure than anything else.
Quote:
> Why do you remove all your controls by yourself? The form will handle the
> disposal of the controls and the occupied memory itself if you close it,
> there is no need to do it yourself (and it can even do more harm, as you
> have experienced yourself). And there is no need to call GC.Collect
either,
> the .NET framework will handle this for you.
> Best regards
> Urs
> > I was having some problems closing my winform on me.close() after
filling
> > the page with my own user controls. After some searching I came across
> > newsgroup articles explaining it was a known bug with Microsoft that
forms
> > don't close in some cases where usercontrols have focus. It turned out
to
> > be a bug in my programming not Microsoft !
> > On closing the form, I remove all controls from page leaving a blank
> screen
> > with 0 controls and then I fire a GC.Collect [ multiple instances of
forms
> > can become a memory hog so I force the clearing of memory on exit of the
> > form ] then finally I call me.close. The page would remove all the
> controls
> > as it should however, the page remained blank and could not be closed.
> > The Cause :
> > ------------
> > You haven't disposed of all the objects and controls on the form
> > The Solution :
> > --------------
> > make sure that you dispose of all your controls, and objects. Even one
> > unclosed object will cause this form to hang and not close. After
> disposing
> > of all my objects properly the form closed without any problems, and the
> > memory released immediately [ via GC.Collect ].
> > AmiT ChandeL