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

Problem in Garbage collector

Shashank Sharma
Ranch Hand

Joined: Sep 27, 2006
Posts: 91
code source:-exam lab question
//at line 9 c.aob and c.aob both are referring to null:
but the object to which B and c are referring to still can be accessed by a.aob as in line4
please help
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

This kind of questions are frequently asked here. You may search a little in the forum and could find many threads which discussed about this. Easiest way to solve these kinds are by drawing an object graph in a paper. Not getting your question though...
//at line 9 c.aob and c.aob both are referring to null:

You are talking about the same reference (i.e: c.aob) here?
but the object to which B and c are referring to still can be accessed by a.aob as in line4

Yes, the reference "a" is still alive (I guess you meant b, not B..).


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

I will expect someone to comment if i am wrong.




so answer of this Question is 1.only 1 object will be eligible for Garbage collection.

SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Try to solve this kind of problem by drawing diagram.It will be good for you and remember the links which got broken will only be eligible for gc if they are not be refer by anyone then.
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

How do we draw object graphs/diagrams? someone got any link that explains it?


OCPJP 6
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

click on this link http://cs.wellesley.edu/~cs111/fall97/lectures/ObjectDiagrams/object-diagrams.html may it will be helpful.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

shanky sohar wrote:I will expect someone to comment if i am wrong.....

There is no use of reference "a" in line#7.
....so answer of this Question is 1.only 1 object will be eligible for Garbage collection.

No. Another one object from line#7 is eligible for GC (the one created in "...new A().aob...).
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

Same question has been discussed here.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

that really a tricky question,one of the great trick play is at line no 7.
now i have corrected my post because of above comment
correct answer is given below.



so now two objects are eligible for gc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Garbage collector