1.

When Does An Object Become Eligible For Garbage Collection? Describe How The Gc Collects An Eligible Object?

Answer»
  • An OBJECT BECOMES eligible for Garbage collection or GC if it is not reachable from any live THREADS or by any STATIC references.
  • The most straightforward case of an object becoming eligible for garbage collection is if all its references are NULL. Cyclic dependencies without any live external reference are also eligible for GC. So if object A references object B and object B references Object A and they don’t have any other live reference then both Objects A and B will be eligible for Garbage collection.
  • Another obvious case is when a parent object is set to null. When a kitchen object internally references a fridge object and a sink object, and the kitchen object is set to null, both fridge and sink will become eligible for garbage collection alongside their parent, kitchen.



Discussion

No Comment Found