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...
 Display...   ensure All Memory (leaks, errors, unleaked) is selected in the first combo box
 ensure All Memory (leaks, errors, unleaked) is selected in the first combo box 
 launch nativeExample.exe  wait until attaching is complete
 wait until attaching is complete  
•Memory tab  Refresh
 Refresh   the display updates to show the usual leaks and memory errors
 the display updates to show the usual leaks and memory errors 
 Managers menu
 Managers menu  Add watermark at most recent trace
 Add watermark at most recent trace  shows the Watermark Name dialog
 shows the Watermark Name dialog 

•Enter a name of your choice, for example 'Low tide'  OK
 OK  adds a named watermark to the system
 adds a named watermark to the system 
•Memory tab  Refresh
 Refresh   the display should refresh to include the new watermark
 the display should refresh to include the new watermark

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

•Memory tab  Refresh
 Refresh   the display should refresh to include the new allocation.
 the display should refresh to include the new allocation.
 Managers menu
 Managers menu  Add watermark at most recent trace
 Add watermark at most recent trace  shows the Watermark Name dialog again
 shows the Watermark Name dialog again 
•Enter a name of your choice, for example 'High tide'  OK
 OK  adds another named watermark to the system
 adds another named watermark to the system 
•Memory tab  Refresh
 Refresh   the display includes the new watermark
 the display includes the new watermark
 
  
 Help menu
 Help menu  About nativeExample.exe...
 About nativeExample.exe...  shows the About box, and deliberately leaks some memory at the same time
 shows the About box, and deliberately leaks some memory at the same time

•Memory tab  Refresh
 Refresh   the display includes the new items.
 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
 Managers menu  Watermark Manager...
 Watermark Manager...  displays the Watermarks dialog
 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
 choose Low tide
•Second  choose High tide
 choose High tide  OK
 OK  changes the watermark settings in the Memory tab to the selected values
 changes the watermark settings in the Memory tab to the selected values
•Memory tab  Refresh
 Refresh   the display changes to including only the data between the selected watermarks
 the display changes to including only the data between the selected watermarks

 
  
 File menu
 File menu  Exit
 Exit

wait for data transfer to complete
•Memory tab  Refresh
 Refresh   the display updates to show leaked items
 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
 Last watermark  select the Last watermark option
 select the Last watermark option

•Memory tab  Refresh
 Refresh   the display updates to show leaked items
 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.
