Name

AllocMemCount Variable

Syntax

var AllocMemCount: Integer;

Description

AllocMemCount stores the number of blocks allocated by Delphi’s memory manager.

Tips and Tricks

  • Delphi doesn’t use the AllocMemCount variable for anything—it is purely for informational purposes. Changing its value, although pointless, is also harmless.

  • If you write your own memory manager, check AllocMemCount before calling SetMemoryManager. AllocMemCount should be zero. If it is not, the default memory manager has allocated at least one block. The problem is that Delphi might try to free that block by calling your custom memory manager. Unless your memory manager can handle this situation, it is safest to halt the program.

  • If you write your own memory manager, you can set AllocMemCount to reflect the number of blocks allocated by your memory manager.

  • If you use DLLs, AllocMemCount might not reflect the blocks allocated in other modules. If you use the ShareMem unit, call its GetAllocMemCount function to count the number of blocks it has allocated for all the modules that use ShareMem.

See Also

AllocMemSize Variable, Dispose Procedure, FreeMem Procedure, GetHeapStatus Procedure, GetMem Procedure, GetMemoryManager Procedure, New Procedure, ReallocMem Procedure, SetMemoryManager Procedure

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.