9.8 Suggestions for Using Heap Walker

One error that frequently occurs in applications is the failure to free memory objects when they are no longer needed. This can cause Windows to fail when one of its data segments grows beyond the 64K limit.

You can use Heap Walker to help determine if your application is not freeing memory objects. With Heap Walker, you can view changes in the sizes of all Windows data segments to observe the effect your application has on these segments.

To check how your application changes the sizes of the Windows data segments, follow these steps:

1.Make sure that your application does not generate fatal exits.

2.Start the debugging version of Windows.

3.Start Heap Walker, and note the sizes of the GDI and USER data segments. This establishes the reference for comparing the size of the data segments later.

4.From the Object menu, choose the GDI LocalWalk command to display the GDI Heap (Local Walk) window, which lists the different objects in the GDI data segment. Then choose the Save command from the Heap menu to copy this list to a file; the file will also contain a summary of GDI objects.

5.Run your application, and exercise it fully over a long period of time, noting the changes in the size of the GDI and USER data segments that Heap Walker displays as your application runs. While your application is running, repeat step 4 a number of times to take “snapshots” of the effect your application has on the GDI data segment.

6.Close your application, take a final snapshot of the GDI data segment, and note the total sizes of the GDI and USER data segments.

As you analyze the data that you've recorded, you should look for GDI objects that your application creates but does not delete when they are no longer needed.