Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
Arka Sharma
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I have a class like this
class A{
B b;
C c;
}

now say in a method I have done

void method()
{
A a = new A();
a.b = new B();
a.c = new C();
a = null;
}

at the point i set reference of class A to null the the object of class A will be removed from heap by GC.Also object for class B and C will be removed right ?
Correct me if I'm wrong.

Thanks,
Arka


 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes since you have no way of accessing them.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12124
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TECHNICALLY, the answer to your question is "No".

At the moment you set A to null, all the objects become ELIGIBLE for GC, but there is no guarantee that they ever will be cleaned up before your program ends.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic