• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how many objects are eligible for GC

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Someone did post same post but I am not getting why c3 is not eligible for GC. I think c3 refers to c2.As soon as cb=null, c2 is null & c3=null.
Why Short wrapper object is eligible?

Can anyone please explain?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is eligible for GC is object not reference variables. c3 has never point to an object. There are two objects of CardBoard type, each of which have a reference to a Short object. Therefore, There are 4 objects. c2 is not assigned to null although cb is because cb only have c2's value when c1.go(c2) is called. cb and c2 are defined in different methods. At last, there are only two objects are eligible for GC, one object of type CardBorad referenced by c1 originally (now c1 is null) and the other object of type Short referenced by the former object. These two objects are isolated island now
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yeming Hu:
At last, there are only two objects are eligible for GC, one object of type CardBorad referenced by c1 originally (now c1 is null) and the other object of type Short referenced by the former object. These two objects are isolated island now

No. In this sample there is only one object eligible for garbage collection. For details have a look here.
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dolly shah:
As soon as cb=null, c2 is null

When you change cb, c2 does not change, since cb is a copy of c2. Have a look at Pass-by-Value Please. It may help you to get the concept.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You knew there is a thread already exisiting, it would have been better if you had continued there itself.
You tell us your understanding of what you know and what you expect the code or run, we can proceed ahead to get you along.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Akhilesh Trivedi:
You knew there is a thread already exisiting, it would have been better if you had continued there itself.
You tell us your understanding of what you know and what you expect the code or run, we can proceed ahead to get you along.



Yes, thats right. Many repeated-but-seems-like-duplicate threads are unnecessarily created and they can be avoided in that way!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic