Once the reference to the object goes out of scope the GC will free the memory that got used for it (whenever the GC does its next collect). If you stop using the object and the reference stays in scope for a long time, set the object reference to null, when the GC next time collects it'll free the object from memory as no references point to it...
e.g.
//use obj here...
obj = null; //finished with obj
//continue processing without obj
note you can also force a garbage collection like:
System.GC.Collect();
Main Topics
Browse All Topics





by: hongjunPosted on 2007-07-19 at 05:20:40ID: 19521180
The garbage collector will dispose it.