• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Garbage Collection doubt

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Amit & Saurabh
 
Everybody's invited. Even this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic