aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection. 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 "Garbage Collection." Watch "Garbage Collection." New topic
Author

Garbage Collection.

Mushraf Khan
Ranch Hand

Joined: May 04, 2011
Posts: 37
Hello, This is my first post on the Forum. I am preparing for SCJP exam. I couldnt clear first attempt(55 %).

I was wondering if anybody could please help me to clear some of my concepts on GC.

This is from Question 4 of Diagnostic Test - Devaka Cooray.
Please could anyone explain how this works. Thanks in advance.



[Thumbnail for Q4.JPG]

Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Hello Mushraf,
welcome to Javaranch!
When it comes to Garbage collection, an image is worth a thousand words, if you REALLY want to solve garbage collection problems ONCE-AND-FOR-ALL practice diagram drawing, it is NOT difficult, it took me ONLY 90seconds to solve this problem.

The answer is ONE object is 'eligible' for garbage collection. Which is the object referenced by 'a2.a'
I guess you REMEMBER that objects are 'eligible' for garbage collection when they have NO 'live reference' variables connecting them.

The ONLY way I can effectively explain this to you is via diagram drawing. (I promise to do that later today).

Regards

Ikpefua.


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

One more thing, while you await my diagram explanation click on this LINK, when you are there scroll down to the bottom of the page, its an example of how I used diagram to resolve a garbage collection puzzle in this forum. Check it out, it might even give you a 'clue' on how I got the answer to your question.
Deepa Sobin
Greenhorn

Joined: May 22, 2011
Posts: 9
Hi Mushraf,

I also agree that one Object is eligible for garbage collection. The one created with newA(null) and to which a2.a was refferring to.

Regards
Deepa
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394



[Thumbnail for Class_A_Heap.jpg]

Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

The numbers placed in the reference variables fletchers correspond to each line of execution in the program I wrote... study it CAREFULLY. If you have doubts, I will be pleased to clarify them.

The diagram clearly demonstrates the answer.

REMEMBER that every instance of this class has its own 'COPY' of the rereference variable 'A a' declared in line 2 of the program.
During instantiation whatever argument you pass to the constructor is assinged to the reference variable
'A a'

I hope this helps.

Regards

Ikpefua.
 
Don't get me started about those stupid light bulbs.
 
subject: Garbage Collection.