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 Android Security Essentials Live Lessons this week in the Android 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

It is sorta covered in the JavaRanch Style Guide.
subject: Doubt in GC
Similar Threads
garbage collection doubt
Garbage Collection
Garbage Collection
Dan exam doubt 19