| Author |
garbage collection
|
Shashank Gokhale
Ranch Hand
Joined: Jan 07, 2003
Posts: 87
|
|
Hi all, I was reading through the Sun tutorials, and it does say that if all the references to an object are set to null, then the object is eleble for garbage collection. But the following confuses me. Its Question #2, and my question is this, if point is set to null, does that not mean that the object that point refers to is now eligible for garbage collection?
|
May the force of the Java be in all of us !!!
|
 |
Chad McGowan
Ranch Hand
Joined: May 10, 2001
Posts: 265
|
|
|
No, because the Rectangle still holds a reference to the Point object. If the rectangle reference was also set to null, both objects would become eligible for gc.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
Chad's correct, you must examine the Rectangle class' code. You can see that the reference to the Point instance passed as a parameter is stored in the instance variable origin. So the Rectangle instance holds on to the Point instance preventing it from becoming eligible for garbage collection.
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Shashank Gokhale
Ranch Hand
Joined: Jan 07, 2003
Posts: 87
|
|
Oh yes, Thanks I see it. I guess I didnt follow the program too closely. My bad
|
 |
 |
|
|
subject: garbage collection
|
|
|