This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in GC" Watch "Doubt in GC" New topic

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

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

Shilpi M Ag
Ranch Hand

Joined: May 07, 2004
Posts: 40

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

I agree. Here's the link:
subject: Doubt in GC
jQuery in Action, 3rd edition