AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Home >
Articles >
Getting Started >
Ada FAQ >
Source Treasury >
Books & Tutorials >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Freeing Pointers to Classwide Types (David Botton)

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;


(c) 1998-2004 All Rights Reserved David Botton