• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in GC

 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of DANS question

class I {
private String name;
public void finalize() {System.out.print(name);}
public I(String s) {name = s;}
}
class J {
private static void m1(I[] a1) {
a1[0] = a1[1] = a1[2] = null;
}
public static void main (String[] args) {
I[] a1 = new I[3]; // 1
a1[0] = new I("A"); // 2
a1[1] = new I("B"); // 3
a1[2] = new I("C"); // 4
m1(a1);
System.gc();
}}

After method m1 returns, the object created on which line is not eligible for garbage collection?


In this //1 is the answer'

How is this , in the first line actually we create an array of size 3 that can hold types of I and in consutive lines we add the reference information to array. Can anybody explain whats happening in the //1 line

Thanks
 
Shilpi M Ag
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The object on line 1 is an array object. So even if you make the individual objects null, the actual array object is not null

Hope that helps

Shilpi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic