Skip to content
EntityQ2010793· pop 5· linked from 74 articles

Also known as finalize method, object finalizer

In computer science, a finalizer or finalize method is a special method that performs finalization, generally some form of cleanup. A finalizer is executed during object destruction, prior to the object being deallocated, and is complementary to an initializer, which is executed during object creation, following allocation. Finalizers are strongly discouraged by some, due to difficulty in proper use and the complexity they add, and alternatives are suggested instead, mainly the dispose pattern (see problems with finalizers).

~23 min read

Article

15 sections
Contents
  • Terminology
  • Use
  • Syntax
  • Implementation
  • Problems
  • Resource management
  • Deterministic and non-deterministic object lifetimes
  • Object resurrection
  • Contrast with initialization
  • Connection with <code>finally</code>
  • History
  • Notes
  • References
  • Further reading
  • External links

In computer science, a finalizer or finalize method is a special method that performs finalization, generally some form of cleanup. A finalizer is executed during object destruction, prior to the object being deallocated, and is complementary to an initializer, which is executed during object creation, following allocation. Finalizers are strongly discouraged by some, due to difficulty in proper use and the complexity they add, and alternatives are suggested instead, mainly the dispose pattern (see problems with finalizers).

The term finalizer is mostly used with programming languages that use garbage collection, such as object-oriented, archetypically Smalltalk, and functional, archetypically ML. This is contrasted with a destructor, which is a method called for finalization in languages with deterministic object lifetimes, archetypically C++. These are generally exclusive: a language will have either finalizers (if automatically garbage collected) or destructors (if manually memory managed), but in rare cases a language may have both, as in C++/CLI and D, and in case of reference counting (instead of tracing garbage collection), terminology varies. In technical use, finalizer may also be used to refer to destructors, as these also perform finalization, and some subtler distinctions are drawn – see terminology. The term final also indicates a class that cannot be inherited; this is unrelated.

Available in 5 languages

via Wikidata sitelinks · CC0

Connections

Categories