This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Set it to null, cleanly exit the methods, release all references and let the Garbage Collector deal with it.
You call tell the GC to fire via the API, but you are not guaranteed it will run "on demand".
Joined: May 22, 2012
Thanks William P O'Sullivan.
I can set the object references to null or I can request GC to get invoked either by System.gc() or Runtime.getRuntime().gc().
If I do either of these two, GC may or maynot fire the instances of the class from the heap.
But what I want to know is other than these, are there any ways to find when an object of a class will perish?
srikanth prasad wrote:When will an object of a class will perish?
Define what you mean by "perish". That is not part of the standard Java lexicon.
If you mean "reclaim its memory," there's no way to force that in Java.
If you mean "make it so that its memory can be reclaimed, so that, as far as my program can tell, the object can no longer be used and its memory is, for all intents and purposes, available," then the answer is to ensure that there are no reachable references to it.
If you mean something else, please clarify.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: When will an object of a class will perish?