One embodiment of the present invention provides a method and a system for
tracking memory usage of tasks in a shared heap. The system performs a
full garbage-collection operation on the shared heap, during which a base
memory usage is determined for each task. The system then periodically
samples task state during execution to generate an estimate of newly
allocated memory for each task. The base memory usage and the estimate of
newly allocated memory for each task are combined to produce an estimate
of current memory usage for each task. This estimate of current memory
usage is used to determine whether a task is likely to be violating a
memory quota. If so, the system triggers a remedial action, which can
include: a full garbage-collection operation; a generational
garbage-collection operation; or generation of a signal which indicates
that a memory quota violation has occurred.