aspose 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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection doubt" Watch "Garbage Collection doubt" New topic
Author

Garbage Collection doubt

Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
Source: Whizlabs

Question: How many objects are elligible for garbage collection by the time finaleze() is invoked?
Options:
1
2
3
Code does not compile
None of the Above

I gave the last option "None of the above" thinking of 4 objects being Garbage Collected. But the answer quotes 2. Is it that the "private MyClass z" is just a reference & not an Object? Can someone Explain me?


SCJP 6 83%
Working on SCWCD/OCPJWCD
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Is it that the "private MyClass z" is just a reference & not an Object?

Yes it is just a reference. Its not instantiated anywhere, just assigned.

Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
Saurabh Vyas
Ranch Hand

Joined: Sep 02, 2003
Posts: 72
To know how many object are actually created on HEAP, what i do is, I look out for the keyword "new". What ever no. of times the keyword "new" appears in the code, that is the actual number of objects that get created on Heap.

Thus in your example, since there are only 3 new keywords so there is no question of 4 objects getting created or coming to existence.
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
Thanks Amit & Saurabh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection doubt