Please enable JavaScript to view this site.

Memory Validator Help

Navigation: Examples

Finding allocations and reallocations

Scroll Prev Top Next More

 

Finding allocations and reallocations

 

You may wish to trace the history of a reallocated memory block.

 

The example program is used to examining where memory was allocated and reallocated.

 

This example is for the CRT, but the same techniques work for

 

Win32 heaps

GlobalAlloc() heaps

LocalAlloc() heaps

CoTaskMemAlloc()

IMallocSpy

user defined (custom allocators) heaps.

 

 

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

 

 

nativeExample1  

 

menu Allocations menu instructionStep C Runtime (C/C++) Heap instructionStep Reallocate memory... instructionStep shows the Test Memory dialog

 

test-memory-dialog

 

Set the following to allocate a 10 bytes block and reallocate it twice, growing in size by 5 bytes each time.

 

Number of bytes to allocate instructionStep set to 10

 

Number of times to allocate instructionStep set to 2

 

Reallocate instructionStep check this

 

Reallocation increment instructionStep set to 5 instructionStep OK

 

 

mvMemVal

 

Memory tab instructionStep Refresh instructionStep the display should refresh to include an item like the one below

 

example-finding-reallocs

 

expand the item instructionStep shows the reallocation history - an allocation and two reallocations

 

example-finding-reallocs-expanded

 

expand the topmost entry in the callstack instructionStep show the source code for the reallocation in CTeststakView::OnTestReallocatememory()

 

Note that the two reallocation locations are the same (because they are in a loop).

 

example-finding-reallocs-expanded2

 

 

mvExample1

 

menu File menu instructionStep Exit