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

chapter 3 self test question 10, K&B

 
Mauricio Archbold Babroza
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why are Five objects were created and Two objects are eligible for GC???
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mauricio. If you search the forum first, you'll find a lot of threads discussing the same problem.
 
Mauricio Archbold Babroza
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
corret me if i wrong,
Dozens [] da = new Dozens[3]; --> 1 object
da[0] = new Dozens(); 2 objects , one is the object dozens and the other is an array of int dz
Dozens d = new Dozens(); 2 objects , one is the object dozens and the other is an array of int dz
 
bhanu chowdary
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes your interpretation is correct.

Earlier you might have missed the array. Array of Dozens is also an Object.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yes there are two objects for garbage collection.



If you see this snippet taken from the code, here first a object of dozens was created and was referenced
by a reference d. Then da[1] also started pointing towards the same dozens object after statement 2. Now
remember that, when you create the the dozens object another array object is also created which is called
da.

If you observe statement 3 and 4 then you can find out now both the references which were pointing towards
the Dozen object has been set to null, so there is no way to access that object nor any alive reference to da,
so now the dozen object and array object both are eligible for garbage collection.

Best Regards,
 
hasi weragala
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
made a rough drawing in paint , so that it will be easy to imagine which objects are going to be available for GC!

 
Jan Cumps
Bartender
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi "De Coder",
Please check your private messages for a JavaRanch administrative matter.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

De Coder, please change your display name to point towards your original name. It is against
the policy of java ranch to put fake names for display.

Best Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic