When memory object is no longer needed, the application uses the DosFreeMem function to release the memory.
If applications do not release memory, the operating system either swaps the memory to the hard disk (if swapping is enabled) or uses memory that could be used by other applications. If OS/2 swaps the memory to the hard disk, the SWAPPER.DAT swap file could become very large. Therefore, applications should release memory as soon as it is no longer needed. Any memory that is still allocated when the application ends is released by OS/2.
DosFreeMem frees a private or shared memory object from the virtual address space of the process. The released pages are returned to the system.
The following code fragment allocates 8192 bytes of committed memory and then releases the memory:
#define INCL_DOSMEMMGR /* Memory Manager values */ #include <os2.h> PBYTE pb; APIRET ulrc; ulrc = DosAllocMem((PVOID *) &pb, 8192, fALLOC); /* Allocate 8KB object */ . . . ulrc = DosFreeMem(pb); /* Free the object */