File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array + GC" Watch "array + GC" New topic

array + GC

ankit goel

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


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

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
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

Joined: Aug 03, 2008
Posts: 9466

Ankit can you please Quote Your Source...

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

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

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

Joined: Jun 06, 2007
Posts: 2851

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

|Asking Good Questions|
ankit goel

Joined: Dec 30, 2008
Posts: 4
question is from kathy sierra 1.6 chapter 3 self test
I agree. Here's the link:
subject: array + GC
jQuery in Action, 3rd edition