File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes chapter 3 self test question 10, K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "chapter 3 self test question 10, K&B" Watch "chapter 3 self test question 10, K&B" New topic
Author

chapter 3 self test question 10, K&B

Mauricio Archbold Babroza
Greenhorn

Joined: Apr 01, 2009
Posts: 11

why are Five objects were created and Two objects are eligible for GC???
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Hi Mauricio. If you search the forum first, you'll find a lot of threads discussing the same problem.


[My Blog]
All roads lead to JavaRanch
Mauricio Archbold Babroza
Greenhorn

Joined: Apr 01, 2009
Posts: 11
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

Joined: Mar 09, 2010
Posts: 256
Yes your interpretation is correct.

Earlier you might have missed the array. Array of Dozens is also an Object.
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
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,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
hasi weragala
Greenhorn

Joined: Jan 22, 2010
Posts: 8
made a rough drawing in paint , so that it will be easy to imagine which objects are going to be available for GC!



My Blog | My Apps | Twitter
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Hi "De Coder",
Please check your private messages for a JavaRanch administrative matter.


OCUP UML fundamental and ITIL foundation
youtube channel
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
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
 
subject: chapter 3 self test question 10, K&B