• 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

Object Create  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class A
{
public static void main(String [] args){
String s = null;


}
}


In this statement Object 's' is created or eligible for garbage collection?
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
S is an object reference pointing to an object. So if s had an object already, then after assigining s to null ( s = null ) the object referred by s will be eligible for GC. In this case none of the objects will be eligible for GC because s was not pointing to any object before initilizing to null.
[ December 15, 2005: Message edited by: Srinivasa Raghavan ]
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you ask about which object available for GC you must specify at what point during the execution are you asking?

Anyways String s = null means only a reference variable is created. No object is created yet so no object is available for GC.
Object is only created using new (ofcourse string is different and object can be created without new also String s = "abcd"
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!