• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array + GC

 
ankit goel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

With these comments...

...what do you think?
 
patrick avery
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this look correct? 5 created, 3 referenced, 2 ready for GC

 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit can you please Quote Your Source...
 
aruna dabas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ARUNA DABAS" can you please adjust your display name so that it does not contain all uppercase letters.
 
ankit goel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
question is from kathy sierra 1.6 chapter 3 self test
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic