Debug Heap Use

If you suspect problems with heap use in your program, you can pinpoint likely causes of heap errors by following these steps:

  1. Compile your program with the /Tm option so that the debug versions of memory management functions are used.
  2. Run your program. Any errors detected by the debug memory management programs are written to standard error, with the source file and line number where the error was detected, and the source file and line number where the heap was last known to be uncorrupted. (You can also run your program within the debugger; in this case, the errors are shown in a popup window instead of on standard error.)
  3. To further isolate a heap corruption error, debug the program, set a breakpoint at the source file and line number where the heap was last known to be uncorrupted, and run the program.
  4. When execution stops at the breakpoint, enable the debugger's own heap checking functions by enabling Run->Check heap when stopping from a Source window or the Session Control window.
  5. Step through your code, or set frequent breakpoints and run it. Each time the debugger stops, it causes your application to call the heap checking functions. When heap corruption is detected, an error message displays in a popup menu.
  6. Each time you see a heap error message and are unable to pinpoint the exact location of the error, note the two line numbers provided, restart the program, set a breakpoint at the line where the heap was last found to be uncorrupted, and use step commands or breakpoints and the Run command to further narrow down the location of the error.


Heap Errors