This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
First there is no way to force garbage collection and this is the most important thing to know about Java garbage collection. The only way to see when your object is being garbage collected is to override the finalize() method and put a trace there. The following thread provides a solution: http://www.coderanch.com/t/238828/java-programmer-SCJP/certification/GC [ August 21, 2002: Message edited by: Valentin Crettaz ]
Hi Tom: Important thing to note here is that garbage collection is about objects (such as Object8 and Object2 in your example) not about references (b1 and b2). Initially, b1 was referencining Object8, then null, then Object2. In the end, b1 and b2 both referenced Object2. The object Object8 is not being referenced by anything in the end and there fore it is candidate for GC. It is possible that it is GCed by the time program was printing. The outcome of the print statements do not prove ( disprove) that Object8 is GCed. Thanks Barkat
Joined: Aug 26, 2001
If you want to know what the gc is doing just run the java interpreter with the -verbose:gc switch.