• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

InitializeComponent memory leak I think

I have a form I request as follows:

dim oform as new frmDASHBOARD

When I close the oform I assume all my managed and unmanaged resources are released.   Well they seem to be relasing, but the initializationcomponents seem not to be releasing.  I have several demo software tools for memory analysis and all indicate that the initializatoncomponent module isn't releasing the objects.

What could I be doing wrong?

I'm at my wits end....

Everytime I start a new oform my memory increases by about 1.2 meg each time.....  never ever releases.....

HELP ................................

1 Solution
have you read through the help file on Garbage collection (and the GC object) ?

There's also a helpful page called "Initialization and Termination of Components"... which appears in the help file under the category "garbage collection"... and sub category "component authoring and"

>> When I close the oform I assume all my managed and unmanaged resources are released.

No they are not.
The memory taken by your oForm will be relaesed only when the Garbage Collector(GC) Runs. And the GC runs when it feels like it.
So if you open a form say (1mb of memory is used) then you close it (still 1 mb used) then open it again ( another 1 mb so now 2 mb used) and s on.

Now when the memory gets filled (almost) our GC will decide its time to clean up, then it will run and clean up the memory.

In case you want that as soon as you close your oForm the memory should be reclaiemd call "GC.Collect" explicilty, However this is not advisable, as the collection process is very resource intensive.
Also, personally I think that it's important to remember that .NET will use as much _free memory_ (not being used by anything else, and won't be impacting performance in a noticeable way) as there is currently available to it.  So if you always have, say, 500 megs of memory free all the time before running your app, then given enough time .NET will fill up a good porportion of that free memory.

As soon anything else in the system needs more memory, then it will be released in the way that arif_egbal has noted.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now