Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!