Example 1: Finding a Multithreading Problem
When a multithreaded program shares memory, problems can occur if one thread deallocated a memory block while another thread is still using it. Because threads execute intermittently, problems are also intermittent. If you hoard memory, the memory will stay viable for longer because it cannot be reused immediately.
If intermittent program failures stop occurring, you know what kind of problem exists.
One advantage of this technique is that you can relink your program (as is described in Chapter 4, Creating Programs for Memory Debugging ) and then run MemoryScape against a production program that was not compiled using the -g compiler debugging option. If you see instances of the hoarded memory, you’ll instantly know problems have occurred.
This technique often requires that you increase the number of blocks being hoarded and the hoard size.