RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.Dispose Function

Releases memory allocated for a dynamic variable.

Pascal
procedure Dispose(var P: Pointer);
C++
Dispose(void * P);

System

Use Dispose in Delphi code to free the memory which a pointer addresses. After a call to Dispose, the value of P is undefined and it is an error to reference P.

Note: If compiling with {$I+}, use exceptions to handle this error. When an invalid pointer is passed to Dispose it raises an EInvalidPointer exception.
 

Delphi Examples: 

 

{
The following code explicitly allocates memory for a pointer
in the OnCreate event of Form1, then releases the memory in
the OnDestroy event. Assume that MyPtr is a Pointer type
field of TForm1.
} 
procedure TForm1.FormCreate(Sender: TObject);
begin
  New(MyPtr);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Dispose(MyPtr);
end;

 

EInvalidPointer 

FreeMem 

GetMem 

New

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!