Given an Ada protected type:
protected type A is
procedure Foo;
...
private
M : Map;
...
end A;
How would you implement or emulate a Finalize procedure that is called when
the protected object is finalized?
Basically I need to do some house keeping using the private members of the protected type (iterating over some map and so on).
Wrap the private members that have a part in the finalization in one or more records derived from Ada.Finalization.Controlled or Limited_Controlled. When the protected object is finalized, those private members will be correspondingly finalized as well.
Here’s a quick, working(!) example:
Running this I get:
The “outer” Initialize/Cleanup messages come are a result of the statically declared Test_Item instance, while the inner pair are from the dynamically allocated and deallocated Test_Item_Handle.