• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question related to Garbage Collector

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True or False
1> GC can be explicitly invoked using runtime object
- True (using System.gc & Runtime.gc )
2> Finalize method is always called before objects are GCed.
- Answer given is True (I feel that objects created without using new which can not be ordinarily GCed are GCed using finalize method. No need to invoke finalize method to gc all the objects).
3> Any class that includes finalize should invoke it's super class finalize method.
-Answer given is True
Can you please answer my query. Thanks in advance!
Regards,
Milind
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answers given are correct. Re: statement 2 - the finalize() method does not cause GC; it's just that if and when an object is about to be GC'ed, the finalize method will be executed first. If the JVM never decides to GC an object, it won't run finalize(). If you invoke finalize yourself for some reason, that won't cause any GC.
Also, when you say "objects created without using new", I assume you mean String literals. All objects other than String literals can be GC'ed normally. Even if you don't see the word "new" in their creation. e.g.
<code><pre>
String a = "sample";
String b = a.toUpperCase();
a = null;
b = null;
// "sample" is literal, and will never be collected
// "SAMPLE" is not a literal, and can be collected
</pre></code>

[This message has been edited by Jim Yingst (edited February 23, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By creating objects without using new, I was hinting at objects created using native methods.
Thanks Jim for the clarification !
Regards,
Milind
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic