*
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

Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42


How many objects are eligible for garbage collection in //line x?
I think there are three objects but I ‘m not sure about “weight” object in Dog class.
Can some one confirm the number?

Thank You
Roman


SCJP 6, SCWCD J2EE 5 http://www.compcoding.com/
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
I think 4 objects are eligible.
m1 ---------> 1st main4 and weight
m2 ---------> 2nd main4 and weight
m3 ---------> 3rd main4 and weight

m3 = m2;
m2,m3 -----> 2nd main4 and weight
xxxxxxxxxxxx 3rd main4 and weight eligible for gc

m1 = m2;
m1,m3,m2----->2nd main4 and weight
xxxxxxxx 1st main4 and weight eligible

m2 = null;
m1,m3 ----> 2nd main4 and weight

m3 = m1;
m1,m3 ----> 2nd main4 and weight


so total 4 object 1st and 3rd main4 with their weights.


SCJP 6
Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42
Thanks Punit,
this is a good explanation.

Roman
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
jayalakshmi charugundla
Ranch Hand

Joined: Jul 22, 2009
Posts: 57
Want to know punit explanation is correct ?

Because kothari you didn't say anything?
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Kothari is jumping, so may be my explanation could be correct
Gustavo Guanilo
Greenhorn

Joined: Sep 24, 2009
Posts: 10
is a very clear explanation I was a little confused with GC .. I am very grateful



Oracle Certified Professional Java Programmer 6.0
Lima-Perú
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
best explanation of gc ever seen by me
Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
Why does weight count as an object? I thought it was just an inherited member?
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
dude its an inherited member that refers to an object......
Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
but weight is a primitive type Long. What object does that refer to?
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
Long is a wrapper which is object not a primitive
Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
Ah so if it had then the answer would be 2 objects.

Thank you Ankur for pointing that out to me
 
 
subject: Garbage Collection