File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about GC and Objects

 
Christian Joseph
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i stumbled about this Test in SCJP by Kat and bertes . ..

on page 274

Which two are true about the objects created within main(), and eligible for garbage collection when line 14 is reached?

the answer is FIVE objects are created and two object are eligible for GC...

can someone help me
explain please
 
Naveen Madarapu
Ranch Hand
Posts: 64
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


if you face this kind of question you need to draw diagram to know which reference is point to which object. which one is eligible to GC.
 
Christian Joseph
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get it now, Thanks! Ms. Naveen Madarapu...

so whenever i say "new Dozens" it will crreate a Dozen Object, PLUS a instance member like the int in the example

then since "d" reference object "NEW DOZENS()" has pointing two f***n thing the "d" and the "d[1]", which is become null, the line broke and then the DOzen of d and the int object, where left on the blackhole

thanks ! did i get it?
 
Ogeh Ikem
Ranch Hand
Posts: 180
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The statement Dozens[] da = new Dozens[3] creates the first object i.e. a Dozens array (1). The statement da[0] = new Dozens() creates 2 objects i.e. a Dozens object (2) and an int array (3). The statement Dozens d = new Dozens() creates 2 objects i.e. a Dozens object (4) and an int array (5). Total objects created is 5.

The statements d = null and da[1] = null make objects (4) and (5) eligible for GC at line 14. Both statements are necessary or else objects (4) and (5) wont be eligible for GC at line 14.

 
Christian Joseph
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ogeh Ikem wrote:The statement Dozens[] da = new Dozens[3] creates the first object i.e. a Dozens array (1). The statement da[0] = new Dozens() creates 2 objects i.e. a Dozens object (2) and an int array (3). The statement Dozens d = new Dozens() creates 2 objects i.e. a Dozens object (4) and an int array (5). Total objects created is 5.

The statements d = null and da[1] = null make objects (4) and (5) eligible for GC at line 14. Both statements are necessary or else objects (4) and (5) wont be eligible for GC at line 14.

THANKS!!! IT REALLY help me alot hearing from you guys!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic