Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Garbage Collection question

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


When "e3 = null;", does that set e3.e to null as well? If not why? It can no longer be referenced. So after "e3 = null;", isn't their one object available for GC?
 
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

Originally posted by Jeff Schuler:
... When "e3 = null;", does that set e3.e to null as well? If not why? ...


It does not set the e3.e reference to null. However, the object that e3.e is pointing to can no longer be reached, and this makes it eligible for garbage collection.

But there is a problem with this code. At runtime, it will throw a NullPointerException at the line e2.e = e1; At that point, e2 is already null, so e2 cannot be dereferenced to get to e2.e.
[ July 28, 2007: Message edited by: marc weber ]
 
Jeff Schuler
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by marc weber:

It does not set the e3.e reference to null. However, the object that e3.e is pointing to can no longer be reached, and this makes it eligible for garbage collection.

But there is a problem with this code. At runtime, it will throw a NullPointerException at the line e2.e = e1; At that point, e2 is already null, so e2 cannot be dereferenced to get to e2.e.

[ July 28, 2007: Message edited by: marc weber ]



Thanks for the reply. This question is referring to a question in K&B book chapter 3. It states that a single object is never eligible for GC even though there is one prior to the runtime exception.
 
marc weber
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

Originally posted by Jeff Schuler:
... This question is referring to a question in K&B book chapter 3. It states that a single object is never eligible for GC even though there is one prior to the runtime exception.


Hmmm... I'm not sure what that means. Did you check the K&B Errata page?
 
Yup, yup, yup. Tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic