A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Joined: Jun 15, 2011
Sep 12, 2011 04:34:48
I have a class like this
now say in a method I have done
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.
Joined: Oct 25, 2008
Sep 12, 2011 04:37:44
Yes since you have no way of accessing them.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Joined: Oct 02, 2003
Sep 12, 2011 07:12:28
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.
Never ascribe to malice that which can be adequately explained by stupidity.
I agree. Here's the link:
- it saves me about five hours per week
subject: Garbage Collection
Garbage Collection on method arguments (from Enthuware)
String vs Object
null as arg in mehods
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013