Watermarks are a really powerful way to partition and associate allocation events to actions or time periods that matter to you and your program.
If you link Memory Validator into your application to use the API, you can also add watermarks (and bookmarks) from within your code.
Using the API to do this is especially useful if your actions or time periods don't map well to user interaction triggers and events.
To demonstrate the use of watermarks we'll run the example application once and add watermarks before and after doing some work.
We'll see a simple case of how to use watermarks to:
•partition allocation events
•reduce data in the display
•help detect memory leaks for specific events
•Memory tab Display... ensure All Memory (leaks, errors, unleaked) is selected in the first combo box
launch nativeExample.exe wait until attaching is complete
•Memory tab Refresh the display updates to show the usual leaks and memory errors
Managers menu Add watermark at most recent trace shows the Watermark Name dialog
•Enter a name of your choice, for example 'Low tide' OK adds a named watermark to the system
•Memory tab Refresh the display should refresh to include the new watermark
Allocations menu C Runtime (C/C++) Heap Allocate memory... shows the Test Memory dialog OK to accept the default values
•Memory tab Refresh the display should refresh to include the new allocation.
Managers menu Add watermark at most recent trace shows the Watermark Name dialog again
•Enter a name of your choice, for example 'High tide' OK adds another named watermark to the system
•Memory tab Refresh the display includes the new watermark
Help menu About nativeExample.exe... shows the About box, and deliberately leaks some memory at the same time
•Memory tab Refresh the display includes the new items.
By now the display looks something like this:
Note the following:
otraces between the watermarks represent objects allocated after the first watermark and before the second
omemory allocated after the second watermark - i.e. when the About Box was displayed.
Without using watermarks, it would not have been obvious which items in the display related to the test allocation, or the about box.
Managers menu Watermark Manager... displays the Watermarks dialog
You should see the watermarks you added earlier, as well as the permanent first and last watermarks in the list.
We'll now use the two watermarks we added, to reduce the data in the display
•First choose Low tide
•Second choose High tide OK changes the watermark settings in the Memory tab to the selected values
•Memory tab Refresh the display changes to including only the data between the selected watermarks
File menu Exit
wait for data transfer to complete
•Memory tab Refresh the display updates to show leaked items
We can see that the allocations that happened between the watermarks are real leaks at the time the program closes.
•Memory tab Last watermark select the Last watermark option
•Memory tab Refresh the display updates to show leaked items
We can now see that the allocations that happened after the High tide watermark are also real leaks.