We help IT Professionals succeed at work.

Object myobject may not be destroyed until it is garbage collected

silentthread2k
silentthread2k used Ask the Experts™
on
I recently converted a VB6 to a VB.NET app, and I received an upgrade note about garbage collecting.

What's with this garbage collecting?

Is this a .NET thing?

Can I collect the garbage?

Can I destroy the garbage?

Why would I want to do my own garbage collecting and then destroying?

Can .NET do both of these tasks for you?

Sorry for all the questions, but I will take simple answers.
UPGRADE_NOTE: Object myobject may not be destroyed until it is garbage collected
myobject = Nothing

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
It is a .NET thing.

Basically thats wrapped around the "managed memory", so you never have memory leaks.  all objects are kept track of by .NET.
At a certain point (many different variables), .NET will determine when the best time to release all remaining unused and unreferenced objects.

Collecting and destroying are the same thing, Collecting means forcing a kill of the objects.

In normal scenarios, not much of a reason for you to do this yourself, but you can with
GC.Collect()
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
The message is simply trying to tell you that the Garbage Collector runs at an indeterminate time...don't expect the physical memory to be immediately released ,or expect the Finalize() event to fire immediately after setting myobject to Nothing.

Setting the variable to nothing allows the object to possibly be FLAGGED for deletion sooner.  The Garbage Collector (not you) decides when to run, however, so you really have no idea when it will actually be released.  Garbage collection is an expensive operation so calling GC.Collect() manually can actually be detrimental to application performance...just depends on the situation.