Home > Language Reference > Functions > System functions
MemCompact Function
Optimizes the memory available in the heap.
Syntax
Public Sub MemCompact(ByVal bGarbageCollector As Boolean, ByVal bCompact As Boolean)
| Parameter | Description |
| bGarbageCollector | Specifies if the garbage collector should be run. |
| bCompact | Specifies if the heap should be compacted. |
Remarks
This function optimizes available memory space in the heap. Normally you do not need to concern yourself with memory management : HB++ and the Palm OS® system cooperate to ensure that all the memory that your application needs is available as far as possible.
However, if your application calls functions in a shared library, HB++ has no way of knowing how much memory these functions require. If you know in advance that these functions will make intensive use of the heap, you can call the MemCompact function before transferring control to the external library.
The bGarbage parameter specifies whether the garbage collector should be run, in other words if HB++ should scan all the existing objects to find those no longer being used. For more information, refer to the Garbage Collector chapter in the Programmer's Guide.
The bCompact parameter specifies if the heap should be compacted, in other words if the system should go through the heap searching for free memory blocks that can be moved and joined together to form bigger blocks of free memory.
In most cases, you will specify both these values to be True.
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |