next up previous contents index
Next: Getdir Up: Functions and Procedures Previous: Frac

Freemem

   

Declaration:

Procedure Freemem (Var P : pointer; Count : longint) ;

Description:

Freemem releases the memory occupied by the pointer P, of size Count, and returns it to the heap. P should point to the memory allocated to a dynamical variable.

Errors:

An error will occur when P doesn't point to the heap.

See also:

Getmem, New, Dispose

Example
Program Example28;

{ Program to demonstrate the FreeMem and GetMem functions. }

Var P : Pointer;
    MM : Longint;
    
begin
  { Get memory for P }
  MM:=MemAvail;
  Writeln ('Memory available before GetMem : ',MemAvail);
  GetMem (P,80);
  MM:=MM-Memavail;
  Write   ('Memory available after GetMem  : ',MemAvail);
  Writeln (' or ',MM,' bytes less than before the call.');
  { fill it with spaces }
  FillChar (P^,80,' ');
  { Free the memory again }                       
  FreeMem (P,80);
  Writeln ('Memory available after FreeMem : ',MemAvail);
end.



Michael Van Canneyt
Thu Sep 10 14:02:43 CEST 1998