wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in garbage collection" Watch "Doubt in garbage collection" New topic
Author

Doubt in garbage collection

Ravi Keshare
Greenhorn

Joined: Feb 02, 2009
Posts: 2
Hi Ranchers,

I had Registered here two moth ago but this is my first post in this forum.

I m preparing for scjp 6 again. yes i had tried it once on Jan 29 (because my voucher is going to expire on jan 31) but failed (51%).

now i am going again for scjp and want to clear this time with 90+.

I had one doubt about the question in devka's diagnostic exam:




Question asked in the mock was "How many objects are eligible for GC after line 12 ?" .

And the answer is "1".

my doubt is that when creating object in the above question, null passed as argument to constructor .

will object be created on the heap (having "null" as value) this way ?

what i thought that there is no object created at all.........i was wrong but need explanation on this. please help.

and please forgive me for my grammatical mistakes......








Preparing for SCJP 6
Kieren Dixon
Greenhorn

Joined: Jan 30, 2009
Posts: 27
Try searching next time.
A thread about this question was posted only two days ago:
http://www.coderanch.com/t/442005/Programmer-Certification-SCJP/certification/many-object-eligible-garbage-collection
Jeena Jeen
Ranch Hand

Joined: Feb 11, 2009
Posts: 47
Sorry Kieren but the link is pointing to a different question. I also have the same doubt as Ravi that whether a new object will be created with a null reference or no object is created?
Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
Please check if some one already raised in the forum when you send any question


SCJP 5 |SCWCD 5| Started thinking about Web Services ?
Kieren Dixon
Greenhorn

Joined: Jan 30, 2009
Posts: 27
Sorry, they looked very similar.

what i thought that there is no object created at all.........i was wrong but need explanation on this. please help.

You are correct, not wrong.
You have probably gotten something else wrong along the way and confused yourself.



So as you can see, there is only 1 object which does not have a reference
Ravi Keshare
Greenhorn

Joined: Feb 02, 2009
Posts: 2
Thanks to you all for replying.

Kieren you explained with great efforts . what i got from it that whenever you say "new" an object is created on heap.
In above question "null" passed as argument to constructor, is actually assigned to an internal object
and this object is the property of an outer object .so outer object has a proper state which proves its existence.
please correct me if i am going wrong.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ravi Keshare wrote: In above question "null" passed as argument to constructor, is actually assigned to an internal object
and this object is the property of an outer object .so outer object has a proper state which proves its existence.
please correct me if i am going wrong.

Yes, but don't use inner/outer object names, people may gets confused it with the inner/outer class. You can say like, "A class contains an instance of other(same) class" OR A HAS a A.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 172
hi i really am still unable to understand as

a1 ----> null

a2 -----> new A() ----> new A() ----> null meaning
a2 -------> null

a3 -------> new A ---> new A() -----> new A() ----> null
meaning
a3 --------> null

a1 = a3

a1.a = null here it should lead to NullPointerException coz a1.a is not reachable coz a1 ------> null

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in garbage collection
 
Similar Threads
SC Exam Lab Question 68 on GC
problem in gc
Doubt over Garbage Collection
Garbage Collector doubt (Examlab Diagnostic Test) Q4
Doubt in Garbage Collection