| Author |
Garbage Collection Problem
|
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
When // doStuff is reached, how many objects are created within main() {specify them} and which one's are eligible for GC?
i think 4 objects would be created i.e.
-c1 and Short variable contained in it
-c2 and Short variable contained in it
----only c1 and it's instance variable Short would be eligible for GC
but i have one doubt would c3 be eligible for GC too ?
|
OCPJP 6.0 93%
OCPJWCD 5.0 98%
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
Please QuoteYourSources.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
Also do you have any guesses of your own about how many objects are eligible for GC??
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
dipayan chatterjee
Ranch Hand
Joined: Oct 03, 2007
Posts: 47
|
|
Hi Mohit
i agree with Ankit , first try out the problem yourself and post what you think the answer would be, we can then identify where you went wrong( if your answer is wrong) in this way you will learn more buddy. so post your answer and we are always there to help you out
|
SCJP1.4 , gearing up for SCWCD 5
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
|
answer posted
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
mohit your answer is right. 4 objects were created and 2 were eligible for GC. As far as c3 goes, it never pointed to any object, it was null. c2 will not be eligible as passing it to go method doesn't makes it null (read this for more info)...
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
IF I REPLACE THE LINE
Short story = 200;
WITH
Short story;
then ,would there be 4 object created or 2 objects as no value would be assigned to story instance variable ?
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
If you don't assign story any value, then it won't point to any object so only 2 objects will be created (as you said yourself)...
|
 |
 |
|
|
subject: Garbage Collection Problem
|
|
|