• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection doubt

 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Saurabh Vyas
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit & Saurabh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic