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.
Is it sure that , output will be same for everytime . Because we are just requesting ( we can't force ) JVM to run GC . And finalize() method is called just before GC for that object . So in my opinion the ouput may differ ...
Please comment ... Thanks .
Joined: Mar 13, 2004
I'd like to hear from someone with access to the Sun Java team, but I think that the gc in the jvm that comes with the j2se sdk is very aggressive in calling finalize() and destroying objects in order to help out students writing test programs like the one in this thread.
A production gc might wait until there is more to clean up.
Also, remember that the production use of calling System.gc() is not to prevent an out of memory condition - we are guaranteed that the jvm will take care of that - but to prevent any slowdown in processing during routine garbage collection from happening at an inconvenient time in a real time program.
The official specification about the unpredictability of gc does not forbid a particular implementation from being more predictable. Of course, the SCJP exam is based on the JLS and API doc and our answers should be as well.
Joined: Oct 11, 2004
So the answer would be unpredictable ( If we have this option ) because in K&B & other cirtification book it is mentioned that we can't force GC by System.gc() this method . Am I right ? Thanks .