One embodiment of the present invention provides a system that facilitates
keeping track of memory usage of tasks in a shared heap. The system
operates by performing a garbage collection operation on the shared heap,
wherein the garbage collection operation is a compacting garbage
collection operation which preserves the ordering of objects within the
shared heap. The system determines a memory usage for each task in the
shared heap by adding the memory usage for intervals containing objects
for each task in the shared heap to the memory usage count for each task
to produce an actual memory usage for each task. This garbage collection
may or may not be a generational garbage collection operation.