This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method

 
RJ Joshi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will an object which has been instantiated in a static method not be removed by garbage collector ?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the static method instantiates an object and the only reference to it is a local variable in the static method, then when the method is over, the object will be available for the gc().
If the static method instantiates an object and the reference to that object is a field outside the method (not a local variable) or is returned out of the static method, then there will be a reference to that object after the static method is complete, and the object will not be available for the gc() until THAT reference is gone also.
 
Jasper Vader
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the static method creates an object but the variable used to reference that object is outside the method, then that variable would have to be static, and would not be available until the entire class has gone away?
ps - i dont know how relevant that situation would e to real life, ie, if it would come up at all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic