aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array + GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array + GC" Watch "array + GC" New topic
Author

array + GC

ankit goel
Greenhorn

Joined: Dec 30, 2008
Posts: 4
No. of objects created and objects available for GC:

code:


class Dozens {
int[] dz = {1,2,3,4,5,6,7,8,9,10,11,12};
}
public class Eggs {
public static void main(String[] args) {
Dozens [] da = new Dozens[3];
da[0] = new Dozens();
Dozens d = new Dozens();
da[1] = d;
d = null;
da[1] = null;
// do stuff
}
}

please help...i am confused....
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

With these comments...

...what do you think?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
patrick avery
Ranch Hand

Joined: Sep 12, 2008
Posts: 46
Does this look correct? 5 created, 3 referenced, 2 ready for GC



SCJA 96%
SCJP 6 88%
skipping SCJD to work on passing SCWCD
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Ankit can you please Quote Your Source...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
aruna dabas
Greenhorn

Joined: Dec 16, 2008
Posts: 27
Hi Ankit i suppose 3 objects Created and one ready for GC.

one object which is referenced by da,second refernced by da[0]and third by d and da[1] both.As reference d and da[1] is set to null,so object refernced by these both whic is a single object is eligible for Garbage Collection.

Thanking You
aruna dabas
Greenhorn

Joined: Dec 16, 2008
Posts: 27
sorry Ankit i forgot to see that each Dozens taht is created comes with its own "int array" object.so with this now i suppose 5 objects created and 2 ready for GC.
Thnak you
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

"ARUNA DABAS" can you please adjust your display name so that it does not contain all uppercase letters.


SCJP, SCWCD.
|Asking Good Questions|
ankit goel
Greenhorn

Joined: Dec 30, 2008
Posts: 4
question is from kathy sierra 1.6 chapter 3 self test
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: array + GC