Please enable JavaScript to view this site.

Memory Validator Help

Navigation: Examples

Using watermarks

Scroll Prev Top Next More

 

Watermarks are your superpower

 

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.

 

 

Example use of watermarks

 

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

 

 

mvMemVal

 

Memory tab instructionStep Display... instructionStep ensure All Memory (leaks, errors, unleaked) is selected in the first combo box

 

launch nativeExample.exe instructionStep wait until attaching is complete

 

Memory tab instructionStep Refresh instructionStep the display updates to show the usual leaks and memory errors

 

menu Managers menu instructionStep Add watermark at most recent trace instructionStep shows the Watermark Name dialog

 

example-watermarks-adding

 

Enter a name of your choice, for example 'Low tide' instructionStep OK instructionStep adds a named watermark to the system

 

Memory tab instructionStep Refresh instructionStep the display should refresh to include the new watermark

 

example-watermarks-lowtide

 

nativeExample1  

 

menu Allocations menu instructionStep C Runtime (C/C++) Heap instructionStep Allocate memory... instructionStep shows the Test Memory dialog instructionStep OK to accept the default values

 

 

mvMemVal

 

Memory tab instructionStep Refresh instructionStep the display should refresh to include the new allocation.

 

menu Managers menu instructionStep Add watermark at most recent trace instructionStep shows the Watermark Name dialog again

 

Enter a name of your choice, for example 'High tide' instructionStep OK instructionStep adds another named watermark to the system

 

Memory tab instructionStep Refresh instructionStep the display includes the new watermark

 

 

nativeExample1  

 

menu Help menu instructionStep About nativeExample.exe... instructionStep shows the About box, and deliberately leaks some memory at the same time

 

 

mvMemVal

 

Memory tab instructionStep Refresh instructionStep the display includes the new items.

 

By now the display looks something like this:

 

example-watermarks-hightide

 

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.

 

menu Managers menu instructionStep Watermark Manager... instructionStep displays the Watermarks dialog

 

You should see the watermarks you added earlier, as well as the permanent first and last watermarks in the list.

 

example-watermarks-manager

 

 

Using watermarks to reduce data in the display

 

We'll now use the two watermarks we added, to reduce the data in the display

 

First instructionStep choose Low tide

 

Second instructionStep choose High tide instructionStep OK instructionStep changes the watermark settings in the Memory tab to the selected values

 

Memory tab instructionStep Refresh instructionStep the display changes to including only the data between the selected watermarks

 

example-watermarks-reduced-data

 

 

Using watermarks to help detect memory leaks

 

nativeExample1  

 

menu File menu instructionStep Exit

 

 

mvMemVal

 

wait for data transfer to complete

 

Memory tab instructionStep Refresh instructionStep 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.

 

example-watermarks-leaks

 

 

Memory tab instructionStep Last watermark instructionStep select the Last watermark option

 

example-watermarks-memory-tab

 

Memory tab instructionStep Refresh instructionStep 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.

 

example-watermarks-leaks-to-last