File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
Shashank Gokhale
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Chad McGowan
Ranch Hand
Posts: 265
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shashank Gokhale
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes,
Thanks I see it. I guess I didnt follow the program too closely. My bad
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic