• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Garbage collection...

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

Pls read the following garbage collection information and let me know how obj2 is eligible for garbage collection.

"If an Object Obj1 is garbage collected, but another object obj2 contains a reference to it, then obj2 is also eligible for garbage collection"

Thanks, Raghu.K
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An object can only be garbage collected if it cannot be referenced from the "active" part of the program.

So if obj1 is garbage collected, this means it cannot be referenced from the active part of the program. Now, if obj2 could be referenced from the active part of the program, then this would provide a way to reference obj1 from the active part of the program. But we know this is not possible, because obj1 is garbage collected. Therefore, it must be that obj2 cannot be referenced from the active part of the program, and so obj2 is eligible for garbage collection.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you can check this thread.
 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear,

I also add one more Input,

Pls check out the following link, it will give you the better picture of Garbage Collector and How it works.

Garbage Collector


Hope it Helps.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic