Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt on finalize()  RSS feed

 
Rakesh Ne
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The source here :
http://www.janeg.ca/scjp/gc/finalize.html

says that finalize is called only once. But I remeber reading somewhere that finalize is called more than once, if the first call to finalize cannot cleanup the object.

Somebody please calrify.

Thanks in advance
 
vanlalhmangaiha khiangte
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An implementation of the finalize() method is called a finalizer.
The finalizer is only called once on an object, regardless of whether any exception is thrown during its execution.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But anyway, finalisation is an almost totally useless feature of Java. As a beginner, it's barely worth thinking about.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, that site listed by the original poster seems full of dubious statements.

For instance, in the bit about finalisation, it recommends using finalisers to close files used by the object. Wrong! Garbage collection should not be used to manage non-memory resources.

In the miscellaneous tips section, there's another: "main() is inherited and can be overridden if not declared as final". Wrong! The main() method is static and hence cannot be overridden under any circumstance. It can be hidden by a subclass method of the same name, but that is not the same at all.

Overall, I'd take the "information" on that site with a big pinch of salt.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!