File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
Roman Mazur
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Punit Singh
Ranch Hand
Posts: 952
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roman Mazur
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Punit,
this is a good explanation.

Roman
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
jayalakshmi charugundla
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Want to know punit explanation is correct ?

Because kothari you didn't say anything?
 
Punit Singh
Ranch Hand
Posts: 952
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kothari is jumping, so may be my explanation could be correct
 
Gustavo Guanilo
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is a very clear explanation I was a little confused with GC .. I am very grateful

 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
best explanation of gc ever seen by me
 
Jack Bento
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does weight count as an object? I thought it was just an inherited member?
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dude its an inherited member that refers to an object......
 
Jack Bento
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but weight is a primitive type Long. What object does that refer to?
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long is a wrapper which is object not a primitive
 
Jack Bento
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah so if it had then the answer would be 2 objects.

Thank you Ankur for pointing that out to me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic