Previous topic | Next topic | Ada Home Page | Index

Deallocation of storage

Storage may be deallocated (released) manually, or you can leave it to the system to do it automatically.

Automatic on procedure exit

Programmer can deallocate space manually


Automatic deallocation

      about to exit                              after exit


Manual deallocation

Code for manual deallocation

    with UNCHECKED_DEALLOCATION;
    procedure main is

        type T  is ... ; -- type definition
        type T_ptr is access T;

        procedure deallocate_T is new
            unchecked_deallocation (T,T_ptr);

        PT : T_ptr;

    begin
          ...
        PT := new T;      -- allocate from heap
          ...
        deallocate_T (PT);  -- return to heap
          ...
    end;


Previous topic | Next topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 27 Feb 96