• Post Reply Bookmark Topic Watch Topic
  • New Topic

garbage collection  RSS feed

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of nested dataobject, is it sufficient to setthe parent object to null after I am done with the data. Or I have to indivially set each object to null.
Thanks
Sri
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you provide some example code?
 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DataObjectOne small = new DataObjectOne();

DataObjectBig big = DataObjectBig();
big.setSmall(small);
After I am done with "big", is it sufficient to make the reference of big to null
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. But if "big" is a local variable that's going to go out of scope soon, you don't even need to do that.
 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what if "big" is a instance variable. when it will be garbage collected. Or how I can I make the "big" instance eligible for garbage collection
 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making an Object(class) as NULL, which has many instance variables declared as new obejcts.
Will that Obejct and and all the instance variable objects will be eligible for garbage collection?
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sri Rangan:
I am making an Object(class) as NULL, which has many instance variables declared as new obejcts.
Will that Obejct and and all the instance variable objects will be eligible for garbage collection?


Yes, unless they are still referenced by other objects in use.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!