aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in GC" Watch "Doubt in GC" New topic
Author

Doubt in GC

maha devan
Ranch Hand

Joined: Mar 16, 2004
Posts: 50
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

Joined: May 07, 2004
Posts: 40
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in GC