Garbage Collection

From Suhrid.net Wiki
Revision as of 04:52, 15 August 2011 by Suhridk (talk | contribs)
Jump to navigationJump to search

Introduction

  • All GC involves in making sure the heap doesnt run out of space.
  • Purpose of the GC is to find and delete objects that cannot be reached.
  • An object is eligible to be garbage collected when no live thread can access it.

Ways in which Objects can be GC'ed

  • Nulling a reference - Explicitly assigning a reference to null will make it eligible for GC.
  • Reassigning a reference - Reassigning the reference to another object will cause older object to be eligible for GC.
    • Local variables in a method will be eligible for GC when the method returns.
  • Isolating a reference - Even if objects have valid references, but still there is no way to reach them, they will be GC'ed.