procedure FreeMem(var P: Pointer; [ Size: Integer]); overload; procedure FreeMem(var P: Pointer; [ Size: Integer]); overload;
FreeMem frees a memory block previously allocated with GetMem.
Use this procedure to dispose of a memory block obtained with GetMem.
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 Mac OS X and iOS platforms, FreeMem does not raise an EInvalidPointer exception if an invalid pointer is passed to Dispose.