If you enable memory debugging, TotalView automatically displays information in the Variable Window about the variable's memory use. The following small program allocates a memory block, sets a pointer to the middle of the block, and then deallocates the block:

1 main(int argc, char **argv)

2 {

3 int *addr = 0; /* Pointer to start of block. */

4 int *misaddr = 0; /* Pointer to interior of block. */

5

6 addr = (int *) malloc (10 * sizeof(int));

7

8 misaddr = addr + 5; /* Point to block interior */

9

10 /* Deallocate the block. addr and */

11 /* misaddr are now dangling. */

12 free (addr);

13 }
[/QUOTE]

The following figure shows two Variable Windows. Execution was stopped before thefree() function on line 12 executes. Both windows contain a memory indicator saying that blocks are allocated.




After the free() function on line 12 executes, the messages change: