File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Island of Isolation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Island of Isolation" Watch "Island of Isolation" New topic

Island of Isolation

Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Hi all, when it comes to practising "garbage collection" concepts, is there anyway we can verify which objects have been garbage collected (say via System.out.println or something equivalent)?

The following code is to test if the objects have been garbage collected before the main method ends:

My current understanding is the makeObj() method created ObjA.

ObjA has a reference of type ObjB (named b) which points to the ObjB created by ObjA.

ObjB in turn, points to ObjA. But nothing else points to this two objects (they point to each other). Therefore they can be garbage collected.

So are these two objects eligible for garbage collection after the makeObj method ends or after the main method ends?
[ July 22, 2006: Message edited by: Shanel Jacob ]
Neelesh Bodas
Ranch Hand

Joined: Jul 20, 2006
Posts: 107
the only reference to ObjA object through the live code is the reference 'test' inside the method makeobj(). As soon as the method ends, the reference ceases to exist and hence both the objects are eligible for GC.

If makeObj would have returned an objA reference, then the two objects would have become eligible for GC only after the completion of main method.
[ July 22, 2006: Message edited by: Neelesh Bodas ]
Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Thank you Neelesh
I agree. Here's the link:
subject: Island of Isolation
It's not a secret anymore!