• Post Reply Bookmark Topic Watch Topic
  • New Topic

GC Question  RSS feed

 
hardikjava shah
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
 
Mary Rachel
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!