This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes garbage collector question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "garbage collector question" Watch "garbage collector question" New topic
Author

garbage collector question

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
Which of the following statements are true?

1) finalize will always run before an object is garbage collected
2) finalize may run before or after an object is garbage collected
3) finalize will run when an object becomes unreachable
4) finalize allows a programmer to free memory allocated to an object


I was trying above question from link
http://www.jchq.net/certkey/0301certkey.htm

Finalize will always be run before an object is garbage collected. It cannot run after it is collected because by then the object will cease to exit. When an object becomes unreachable it will be eligible for garbage collection but there is no guarantee when finalize will run, only that it will run before garbage collection happens. The final option is a passable description of destructors in C++ but not of the finalize method in Java.

I have not understood clearly explanation in terms of relation between garbage collection and finalize method. Any ideas, resources, links, sample code highly appreciated. thanks in advance.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Effective Java by Joshua Bloch; there are details here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: garbage collector question
 
Similar Threads
Question on garbage collection from mock exam
GC
Question on Garbage Collection
Garbage collection
Question on garbage collection