File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collector doubt (Examlab Diagnostic Test) Q4 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 Collector doubt (Examlab Diagnostic Test) Q4" Watch "Garbage Collector doubt (Examlab Diagnostic Test) Q4" New topic
Author

Garbage Collector doubt (Examlab Diagnostic Test) Q4

Sridhar Gudipalli
Ranch Hand

Joined: Nov 02, 2005
Posts: 120
source: (Examlab Diagnostic Test) Q4

Q. How many objects are eligible for Garbage Collector, after executing the Line-12 of the following program?


I am confused to solve this problem. Any clue would be highly appreciated.


Sridhar Gudipalli|SCJP 6.0
SCWCD objectives
Joshua Antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 254
You have to analyse this using pen and paper, find out how many objects are created in total and then check out how many gets derefrenced.
I guess 4 new objects are created in this scenario and finally 1 becomes eligible for GC

Cheers-
Joshua


SCJP,SCWCD, Into ATG now!
Rufat Piriyev
Ranch Hand

Joined: Mar 15, 2010
Posts: 31
Sridhar Gudipalli wrote:source: (Examlab Diagnostic Test) Q4

Q. How many objects are eligible for Garbage Collector, after executing the Line-12 of the following program?


I am confused to solve this problem. Any clue would be highly appreciated.

I am confused too, but IMHO 0 object ?
There is a scheme but I 'm not sure 100%






[Thumbnail for 22052010(004).jpg]

Sridhar Gudipalli
Ranch Hand

Joined: Nov 02, 2005
Posts: 120
Rufat Piriyev wrote:
I am confused too, but IMHO 0 object ?
There is a scheme but I 'm not sure 100%


Thanks for trying to solve. But the answer is 1. I tried to draw this object creation. But still not clear with the flow.
Joshua Antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 254
Answer is 1 because a2.a=null frees an object therby making it eligible for GC. I am sure you can find out if you try a bit harder

Cheers-
Joshua
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Answer is clearly 1.

a2-->[ Object A1 (IV) ]---->Object A2
a3--->[Object A3 (IV) ]---->Object A1
a1---->Object A3
[Object A3 (IV) ] ---->Object A4
Line12 a2.null cause AI object to be eligible for Garbage Collection.


Note:- [Object A1 (IV) )----> by this link i mean Object A1's Instance Variable(IV) is Pointing to

I have numbered Object A's just to make it bit easier....so A1 A2 A3 and A4 are all Object A.

Thanks !!!

SCJP 6.0 96%

(Connecting the Dots ....)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Garbage Collector doubt (Examlab Diagnostic Test) Q4
 
Similar Threads
SC Exam Lab Question 68 on GC
help on Garbage Collection analysis
Garbage Collection
AFTER which line, only one object is eligible for GC - From Examlab (Practic Exam-1)
problem in gc