- Posted by: Tarun Dewan
- Posted on: September 04 2003 02:41 EDT
Do we need to set the object (except connection etc.) variable as null to release the same from memory and to be marked for Garbage Collector or it is done automatically as soon as object is out of current scope execution.
Thanks & regards,
keeping null for garbage collector is good practice.But garbage collector will take care too destroy the variables once refrences to those variables are destroyed.
Setting to null will only mark an object for garbage collection if there are no other references to it.
So all references to the the object must have either fallen out of scope or been assigned to something else (such as null) for garbage collection to pick it up.
You can understand about garbage collection at http://www.java4all.info/articles/corejava/garbage-collection-java.html