• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Garbage collection

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

https://coderanch.com/t/457125/Programmer-Certification-SCJP/certification/Garbage-collection
https://coderanch.com/t/456750/Programmer-Certification-SCJP/certification/Number-objects-Array
https://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.
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic