• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

objects created on the heap and those eligible for gabage collection

 
Harold Ndou
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Dozens {
int[ ] dz = {1,2,3,4,5,6,7,8,9,10,11,12}
public class Eggs {
public static void main( String [] arg) {
Dozens [ ] da = new Dozens[3];
da[0] = new Dozens();
Dozens d = new Dozens();
da[1] = d;
d = null;
da [1] = null;
// do stuff
}
}
The answer is: five objets were created and two objects are elegible for gabage collection(C and F in the K & B study guide, chapter 3 self test question 10 on page 283

I have problem trying to understand the number of objects created within main () method, and those that are eligible for garbage collection. Can anyone assist me, i wil greatly appriciate it.
 
Arnab Sunny Rakshit
Greenhorn
Posts: 19
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to explain it in the Screenshot below.
Screenshot_2013-06-08-06-48-48.png
[Thumbnail for Screenshot_2013-06-08-06-48-48.png]
 
Harold Ndou
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Arnub

I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic