This week's book giveaway is in the Spring forum.
We're giving away four copies of Modern frontends with htmx and have Wim Deblauwe on-line!
See this thread for details.
Win a copy of Modern frontends with htmx this week in the Spring forum!
  • 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

GC

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The finalize() method is guaranteed to be called on any object to be GC�ed
True or False?
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Siva Sivaraman:
The finalize() method is guaranteed to be called on any object to be GC�ed
True or False?


True. From the JLS, section 12.6:
Before the storage for an object is reclaimed by the garbage collector, the Java virtual machine will invoke the finalizer of that object.
However, a particular object may never be garbage collected, so its finalize() may never be called.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Siva Sivaraman:
The finalize() method is guaranteed to be called on any object to be GC�ed
True or False?


I'd say True -
this question is a little tricky ...
we know that actual garbage collection is never guaranteed when we make calls such as "Runtime.getRuntime.gc() or System.gc() however,
According to the book "Mike Meyer's Certification Passport Java 2" written by Glass,Griscti, Isayeva, Kallambella, Sierra

(pg.129) "Every object inherits a finalize() method from java.lang.Object class.
The garbage collector is garunteed to invoke this method once prior to reclaiming the object's memory"


And another book "Java 2 Sun Certified Programmer Study Guide" 2nd Edition from Osborne states:

"Every class has a special method called a finalizer that is called just before an object is collected. The JVM calls the finalizer for you as appropriate; you never call a finalizer directly."

 
Siva Sivaraman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to you all.
Didn't want to be trapped with such tricky questions.
The finalize() method is guaranteed to be called on any object eligible for GC.
True or False?
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic