• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

GC Question  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The object created on line 1 is eligible for GC after which line?

public class test extends supertest{
static void f(String[] s)
{
s=null;
}

static void g(String[] s)
{
s=new String[2];
}

static String[] h(String[] s)
{
return new String[2];
}

public static void main(String args[])
{
String s[] = new String[2];//1
f(s);//2
g(s);//3
s=h(s);//4
s=null;//5
}
}

2,3,4,5, or none
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi shah,

I think 's' will be eligible for GC after line 4.
here s is reassigned to another string array object h(s).
so after this line 4 executed it will be eligible for Garbage Collection.

-Mary Rachel
 
hardikjava shah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm .. Got it. Now when I think again about it

Thanks alot!
Hardik
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!