aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to make the map of object to be garbage collected 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to make the map of object to be garbage collected" Watch "How to make the map of object to be garbage collected" New topic
Author

How to make the map of object to be garbage collected

nitude gupta
Ranch Hand

Joined: Sep 04, 2008
Posts: 34
Hi ,
I am giving SCJP1.5
I am seriously facing problem in calculating objects which will be garbage collected.
Lets take an example from Devaka's examulator


Question is how many objects are eligible for garbbbage collection after Line1?
P.S:I have typed the code they may be some grammatical mistake please ignore.

My problem is how to make map of objects to be garbbage collected

I am really bugged.
Please help!!!

Adi Kulkarni
Ranch Hand

Joined: Mar 12, 2009
Posts: 86
In this case two objects will be eligible for garbage collection. One created in line 16 and one created in line 17.

Whenever you are trying to deal with such examples.
1: Draw a heap ( a rectangle)

2: draw every object created and the reference variable pointing to it. In this case since the class A has two reference variables a1 and a2 ,they are the class members. every new object created will have these in the object.

3: The is only one explicit reference variable to the object created in first line of main. Rest all are implicit ones.

4: At line 19 , the reference is made null and there is no reference to the object created on line 16. and hence it is eligible since it doesnt have any direct / indirect reference. The object created on line 17 is referenced by a2 variable of the object created in line 16. Since Object(16) is already eligible for GC , object(17) is also eligible.

I know its confusing . Please try to read the "Islands of isolation" from the KB book.

~Aditya


SCJP 1.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make the map of object to be garbage collected
 
Similar Threads
exam lab gc question
Garbage Collection
Doubt over Garbage Collection
Garbage collection question from Exam lab
Confusion in Garbage Collection