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.

After calling FreeMem, the value of the P parameter is undefined.

FreeMem has two overloaded procedures.

The second procedure adds an optional Size parameter that is obsolete and only used for backward compatibility.

Attention: FreeMem is not available in C++. Instead, you can use FreeMemory.
Note: 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