From RAD Studio API Documentation
Jump to: navigation, search


procedure FreeMem(var P: Pointer); overload;
procedure FreeMem(var P: Pointer; Size: NativeInt); overload;


Type Visibility Source Unit Parent
procedure public System.pas System System


FreeMem frees a memory block previously allocated with GetMem.

Use this procedure to dispose of a memory block obtained with GetMem.

The Size parameter specifies the size, in bytes, of the dynamic variable to dispose of; if specified, it must be exactly the number of bytes previously allocated to that variable by GetMem.

After calling this procedure, the value of the P parameter is undefined.


  • FreeMem is not available in C++. In C++ you can use FreeMemory.
  • If a pointer to unallocated memory is passed to FreeMem, the behavior of the application largely depends on the target platform, as follows:
    • For Windows platforms, an EInvalidPointer is raised in applications using System.SysUtils, and a run-time error is produced for applications that do not use System.SysUtils. (FastMM, the default memory manager, can detect an invalid pointer.)
    • For OS X and iOS platforms, FreeMem does not raise an EInvalidPointer exception if an invalid pointer is passed to Dispose.

See Also

Code Examples