Controlled Types
Overview
In this section, we introduce the concept of controlled types. We start with a review of lifetime of objects and discuss how controlled types allow us to control the initialization, post-copy (e.g. assignment) adjustment and finalization of objects.
Relevant topics
Lifetime of objects
We already talked about the lifetime of objects previously in the context of access types. Again, we assume you understand the concept. In any case, let's quickly review the typical lifetime of an object:
In simple terms, an object A is first created before we can make use of
it. When object A is about to get out of scope, it is finalized.
Note that finalization might not entail any actual code execution — but
it often does.
Let's analyze the lifetime of object A in a procedure P:
procedure P is
A : T;
begin
P2 (A);
end P;We could visualize the lifetime as follows:
[