Freeing Pointers to Classwide Types
Freeing pointers to classwide types is done in the same way as freeing any pointer to a type, using Ada.Unchecked_Deallocation.
with Ada.Unchecked_Deallocation;
procedure testfree is
type Object is tagged
record
Test : Integer;
end record;
type Object2 is new Object with
record
More_Stuff : Integer;
end record;
type Pointer is access all Object'Class;
procedure Free_Object is new
Ada.Unchecked_Deallocation(Object'Class, Pointer);
-- Note the use of the classwide type Object'Class
X : Pointer := new Object;
Y : Pointer := new Object2;
begin
Free_Object(X);
Free_Object(Y);
end testfree;
Contributed by: David Botton
Contributed on: January 4, 1999
Last Updated: September 20, 2000
License: Public Domain
Back