1 package Garbage_Collected
is
3 -- A generic would not be convenient for lists. We want the
4 -- extended type to be able to have a discriminant.
6 -- However, we keep the dispatching in a single enumeration for
7 -- efficiency and clarity of the source.
9 type Instance
is abstract tagged limited private;
10 subtype Class
is Instance
'Class;
11 type Link
is access all Class
;
12 subtype Pointer
is not null Link
;
14 procedure Keep_References
(Object
: in out Instance
) is null with Inline
;
15 -- A dispatching call in Keep allows subclasses to override this
16 -- in order to Keep each of the internal reference they maintain.
18 -- The following methods have no reason to be overridden.
20 procedure Keep
(Object
: in out Class
) with Inline
;
21 -- Mark this object so that it is not deleted by next clean,
22 -- then make a dispatching call to Keep_References.
23 -- Does nothing if it has already been called for this object
24 -- since startup or last Clean.
26 procedure Register
(Ref
: in Pointer
) with Inline
;
27 -- Each subclass defines its own allocation pool, but every call
28 -- to new must be followed by a call to Register.
31 -- For each object for which Keep has not been called since
32 -- startup or last clean, make a dispatching call to Finalize,
33 -- then deallocate the memory for the object.
36 procedure Check_Allocations
;
37 -- Does nothing if assertions are disabled.
41 type Instance
is abstract tagged limited record
42 Kept
: Boolean := False;
46 end Garbage_Collected
;