• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection

 
Rajni Patel
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
topic : Garbage collection

could you explain me what is result and how?

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 Dozebs[3];
da[0] = new Dozens();
Dozens d = new Dozens;
da[1] = d;
d = null;
da[1] = null;
// do stuff
}
}

how many objects will create and how many objects are eligible for garbage collection when line 14 is reached?
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well How many do you think is eligible? Also this question is discussed many times in the forums. Please search it.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

If you search for "Dozens", you will find a few older topics in which the same question was discussed, for example:

http://www.coderanch.com/t/457125/Programmer-Certification-SCJP/certification/Garbage-collection
http://www.coderanch.com/t/456750/Programmer-Certification-SCJP/certification/Number-objects-Array
http://www.coderanch.com/t/454321/Programmer-Certification-SCJP/certification/capitulo-kathy-sierra-book

One more important thing: When you copy a question from a book, mock exam or other source, please quote your sources - tell us where you copied it from. That's required on JavaRanch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic