Debugging Memory Problems with MemoryScape : Chapter 2 Memory Tasks : Task 15: Hoarding Deallocated Memory

Task 15: Hoarding Deallocated Memory
Hoarding is not an often-used feature. It is most often used to prevent problems related to memory being deallocated by one part of the program and another part using this memory, not knowing it is deallocated. For two examples of how hoarding is used, see Hoarding”.
Before reading this task, you should be familiar with the following information:
Chapter 1, “Locating Memory Problems”
Contains an overview of memory concepts and MemoryScape.
Task 1: “Getting Started”
Tells you how to start MemoryScape. It also contains an overview of the kinds of information you can ­obtain.
Task 3: “­Setting MemoryScape Options”
Describes configuring MemoryScape so that it performs the activities you want it to perform.
Task 4: “Controlling Program Execution”
Shows how to start and stop program execution.
Tell MemoryScape to hoard memory by selecting the Memory Debugging Options screen. (This is described in Task 3: “­Setting MemoryScape Options”.) Next, select Extreme. If you need to tune how MemoryScape hoards memory, select Advanced Options. Figure 73 shows the portion of the options page where you set hoarding options.
 
Hoarding is actually a very simple process. When your program deallocates memory, MemoryScape stashes the deallocation request away. It also records some information about the size of the block that would have been deallocated. And then it ignores the deallocation request.
Ignoring the deallocation request means that the memory stays “good” and other parts of the program can continue to access this good information instead of using data that may have incorrect values. Said differently, the program can keep executing with the correct information a while longer. This improves your chances of finding where the problem is.
MemoryScape doesn’t just keep ignoring your program’s deallocations request. By default, MemoryScape hoards 32 requests. Also by default, it only defers the deallocation of up to 256 KB of memory. You can, of course, change either of these values by using MemoryScape options.
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.

Rogue Wave Software, Inc.
Voice: (303) 473-9118
rwonlinedocs@roguewave.com