Debugging Memory Problems with MemoryScape™ : Chapter 1 Locating Memory Problems : Hoarding
Hoarding
You can stop your program’s memory manager from immediately reusing memory blocks by telling MemoryScape to hoard (that is, retain) blocks. Because memory blocks aren’t being immediately reused, your program doesn’t immediately overwrite the data within them. This allows your program to continue running with the correct information even though it is accessing memory that should have been deallocated. Because it has been hoarded, the data within this memory is still correct. If this weren’t the case, any pointers into this memory block would be dangling. In some cases, this uncovers other errors, and these errors can help you track down the problem.
If you are painting and hoarding deallocated memory (and you should be), you might be able to force an error when your program accesses the painted memory.
MemoryScape holds on to hoarded blocks for a while before returning them to the heap manager so that the heap manager can reuse them. As MemoryScape adds blocks to the hoard, it places them in a first-in, first-out list. When the hoard is full, MemoryScape releases the oldest blocks back to your program’s memory manager.
To hoard all deallocated memory, set the maximum KB and blocks to unlimited by entering 0 in the hoarding control fields. To prevent or delay your program from running out of memory when you use this setting, use the advanced option to set MemoryScape to automatically release hoarded memory when available memory gets low.
You can also set a threshold for the hoard size so MemoryScape can warn you when available memory is getting low. If the hoard size drops below the threshold, MemoryScape halts execution and notifies you. You can then view a Heap Status or Leak report to see where your memory is being allocated.