In
object-oriented programming,
finalization is the process of preparing an object for
deallocation; strictly speaking, finalization is all parts of
object destruction until memory deallocation itself. Finalization is formally complementary to
initialization, which is the part of
object creation that follows
allocation, but differs significantly in practice – see contrast with initialization. Finalization fulfills a similar role as
finally
in
exception handling; in general these are unrelated, but in some cases the behavior is identical, and the case of
finally
in a
coroutine can be considered a form of finalization – see connection with finally. The term "final" is also used to indicate a class that cannot be
inherited; this is unrelated.