• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

is this object eligible for garbage collection??  RSS feed

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

is the object 's' eligible for garbage collection at line 3 ??
 
Ranch Hand
Posts: 110
Firefox Browser Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.When the object has no references, in the given example when the end of the main() method is reached, then it is eligible for garbage collection.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi



I dont think the object referred by s will be available for GC at LINE3 because it has the refernce, s, now also. An object will be available for GC, when it don't have any live references.
In my opinion, it will be available for GC at LINE 4, ie, by the end of that method
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An object is eligible for garbage collection when there is no direct or indirect reference to it.

In this case at Line 3 there is still a reference to the StringBuffer object. The object would be eligible for garbage collection when the program goes out of scope. If you want to make it eligible for GC before the main method goes out of scope make all the references to it null explicitly.
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!