Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

A quote from Khalid A Mughal

 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the explaination for review question 8.1 on page 643, the author says:


An object is only eligible for garbage collection if the only references to the object are from other objects that are also eligible for garbage collection. Therefore if an object obj2 is eligible for gargabe collection and object obj1 contains a reference to it , than object obj1 must also be eligible for gargage collection.


With my understanding of garbage collection the bolded part should say:

Therefore if an object obj2 is eligible for gargabe collection and it contains a reference to object obj1 which is the only reference to obj1, than object obj1 must also be eligible for gargage collection.

Please let me know, if I am mistaken.
Thanks
Barkat
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, If there is NO reference for an object then it can be garbage collected.
If the object (obj1) has a reference in another object (obj2) then it can NOT be garbage collected.
BUT another case is that:
If the object (obj1) has a reference in another object (obj2) that has no references itself and thus (obj2) can be garbage collected, then (obj1) can be garbage collected.
Now if you take the last case and reverse its logic, you get the meaning of the quote from Mughal's: Again
If the object (obj1) has a reference in another object (obj2) then it should be that (obj1) can't be garbage collected BUT if (obj1) can be garbage collected - although it has a reference to it in (obj2) - then the only reason it can be garbage collected is that (obj2) itself has no references and can be garbage collected
Blocks in bold relate to each other and the ones in Italics relate to each other
Hope that made it clear. not more confusing
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your post Alfred. I am still not clear.
 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply put.
if (obj1 has reference in obj2 & obj1 is eligible for garbage collection)
Obj2 must also be eligible for garbage collection.
if you don't know what Obj1 has a reference in obj2 means then your problem is not in the garbage collection part, you should re-read the part of language fundamentels and the part of aggregation, the relation has-a.
HTH
[ October 17, 2002: Message edited by: Alfred Kemety ]
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic