The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Garbage collection again

Posted by Kumar on January 22, 2001 at 11:29 PM

Yes, I agree that it is a good idea to set an object to null to inform the GC that it can go ahead and release the memory.

But, I assume that the GC will be intelligent enough to know that for local automatic variables(objects) it will go ahead and release the memory for the object once the object is out of scope (when you exit the function). Do we need to explicitly set the object to null even in this case.
I am not sure if this topic is addressed in great detail. I don't want my team of programmers to go overboard and go about setting all objects to null once they have used them.
My personal opinion to this is that GC should have enough intelligence to detect that a local variable is going out of scope and that no other object has reference to the local object.
Can you throw more light on what is the language stand on this?


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us