Checking for Problems
MemoryScape can help you locate many of your program’s memory problems. For example, you can:
Stop execution when free(), realloc(), and other heap API ­problems or actions occur
For example, if your program tries to free memory that it either can’t or shouldn’t free, MemoryScape can stop execution. This lets you quickly identify the statement causing the problem. For more information, see Finding free() and ­realloc() Problems.
Or, after identifying a memory block, you can tell MemoryScape to stop execution when your program either deallocates or reallocates it. For more information, see Deallocation and Reuse Notifications.
List leaks
MemoryScape can display reports of your program’s leaks—leaks are memory blocks that are allocated and are no longer referenced; that is, the program no longer can access the memory block, which means that memory is not available for any other use.
When your program allocates a memory block, MemoryScape creates and records a backtrace for the block—a backtrace is a list of stack frames. At a later time when you ask MemoryScape to display leak information, MemoryScape also displays this backtrace. This means that you’ll instantly know where your program allocated the memory block. For more information, see Finding Memory Leaks.
Locate memory written beyond the bounds of an allocation
MemoryScape can allocate memory immediately before and after the blocks your program allocates. When MemoryScape adds these blocks—called guard blocks—it also initializes them to a bit pattern. If this bit pattern changes, MemoryScape sees the change when your program deallocates the block, and stops execution.
MemoryScape can also check all guard blocks at any time during program execution. For more information, see Using Guard Blocks.
Another option is to use Red Zones, additional pages of memory allocated before or after your block. MemoryScape can apply Red Zones to your allocated blocks. If MemoryScape detects read or write access in the Red Zone outside the bounds of your allocated block, it halts program execution and notifies you of the underrun or overrun. For more information see Using Red Zones.
Paint allocated and deallocated blocks
When your program’s memory manager allocates or deallocates memory, MemoryScape can write a bit pattern into it. Writing this bit pattern is called painting.
If your program tries to dereference a pointer through painted memory, it may crash. Fortunately, MemoryScape will trap the action before your program dumps core, allowing you to see where the problem occurs. For more information, see Block Painting.
Hold on to deallocated memory
When you are trying to identify memory problems, holding on to memory after your program releases it can sometimes help locate problems by forcing a memory error to occur at a later time. Holding onto freed memory is called hoarding. For more information, see Hoarding.