Generalized Finalization (GNAT Reference Manual) (original) (raw)


17.3.7 Generalized Finalization

The Finalizable aspect can be applied to any record type, tagged or not, to specify that it provides the same level of control on the operations of initialization, finalization, and assignment of objects as the controlled types (see RM 7.6(2) for a high-level overview). The only restriction is that the record type must be a root type, in other words not a derived type.

The aspect additionally makes it possible to specify relaxed semantics for the finalization operations by means of the Relaxed_Finalization setting.

Example:

type Ctrl is record Id : Natural := 0; end record with Finalizable => (Initialize => Initialize, Adjust => Adjust, Finalize => Finalize, Relaxed_Finalization => True);

procedure Adjust (Obj : in out Ctrl); procedure Finalize (Obj : in out Ctrl); procedure Initialize (Obj : in out Ctrl);

The three procedures have the same profile, taking a single in out Tparameter.

We follow the same dynamic semantics as controlled objects:

However the following differences are enforced by default when compared to the current Ada controlled-objects finalization model:

Additionally, two other configuration aspects are added,Legacy_Heap_Finalization and Exceptions_In_Finalize: