One embodiment of the present invention provides a system for managing
surplus memory in a multitasking system. The system operates by reserving
a guaranteed amount of memory from a heap for a task. Heap memory not
reserved for a task is surplus memory. When the system receives a request
from the task to allocate memory for a new object, the system determines
if memory is available within the guaranteed amount of memory. If so, the
system allocates memory for the new object from the guaranteed memory.
Otherwise, if available, the system reserves an additional amount of
memory to the task from surplus memory in the heap. The system then
allocates memory for the new object from the additional amount of memory.
Allocating memory for the new object from the additional amount of memory
delays garbage collection of the memory. Surplus memory can be
transparently reclaimed.