Ada.Finalization.Controlled
¶Ada.Finalization.Controlled
is now specified as:
type Controlled is abstract tagged null record with Initialize => Initialize, Adjust => Adjust, Finalize => Finalize, Legacy_Heap_Finalization, Exceptions_In_Finalize; procedure Initialize (Self : in out Controlled) is abstract; procedure Adjust (Self : in out Controlled) is abstract; procedure Finalize (Self : in out Controlled) is abstract;
### Examples
A simple example of a ref-counted type:
type T is record Value : Integer; Ref_Count : Natural := 0; end record; procedure Inc_Ref (X : in out T); procedure Dec_Ref (X : in out T); type T_Access is access all T; type T_Ref is record Value : T_Access; end record with Adjust => Adjust, Finalize => Finalize; procedure Adjust (Ref : in out T_Ref) is begin Inc_Ref (Ref.Value); end Adjust; procedure Finalize (Ref : in out T_Ref) is begin Def_Ref (Ref.Value); end Finalize;
A simple file handle that ensures resources are properly released:
package P is type File (<>) is limited private; function Open (Path : String) return File; procedure Close (F : in out File); private type File is limited record Handle : ...; end record with Finalize => Close;