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 Garbage collection doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collection doubt" Watch "Garbage collection doubt" New topic
Author

Garbage collection doubt

Mahmoud Metwaly
Greenhorn

Joined: Jul 16, 2008
Posts: 14
Assuming we have the following method



Now by exiting this method, how many objects are eligible for garbage collection 4 OR 5 (if we are going to count 4 objects of the array + the array object itself)?


Thanks in advance


Mahmoud Metwally<br />Preparing for SCJP...<br /> <br />"Try not to become a man of success but a man of value" - Albert Einstein
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
I'm going to take a guess and say one.

Here's why I say that: the statement instantiates an array large enough to hold four String references..... and then nulls them all. They do not contain instances of strings yet. So I think that the only object there is the array.
[ July 29, 2008: Message edited by: Bob Ruth ]

------------------------
Bob
SCJP - 86% - June 11, 2009
Lino Larios
Greenhorn

Joined: Jun 27, 2008
Posts: 28
I think that one only object the array , because the array is just holding 4 references variables
[ July 29, 2008: Message edited by: Lino Larios ]
Ronald Schild
Ranch Hand

Joined: Jun 09, 2008
Posts: 117
Only the array object. All the references in the array are set to null as default value, and no String objects are created.


Java hobbyist.
Vinod Kumar Kommineni
Ranch Hand

Joined: Jun 12, 2008
Posts: 54

ya its only one object ... since they are not intialised to refer any object


Regards
vinod SCJP 6.0
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Garbage collection doubt
 
Similar Threads
Garbage collection
I Am Not Tired of Garbage Collection Yet
Qustion about Garbage Collection
garbage collection
Garbage Collection