Please enable JavaScript to view this site.

Memory Validator Help

Navigation: The User Interface > Query and Search

Finding allocations deallocated in different threads

Scroll Prev Top Next More

 

 

Cross-threaded allocations

 

Cross-thread allocations are when memory is allocated in one thread, and is deallocated or reallocated in another thread.

 

Memory Validator connects these events, as well as resource handle allocations and releases.

 

Cross-thread allocations are perfectly valid, for example, a main thread may place data objects onto a queue in a worker thread that deletes them after processing.

 

However, the practice can also result in unintentional behaviour as well. For example, after a process that started off single threaded has been made multi-threaded.

 

Often these errors occur when memory is unexpectedly deallocated in a diffferent thread.

 

Using the cross-thread allocations dialog below, you can find these cross-thread allocations and deallocations.

 

By inspecting them you can verify expected behaviour, and look out for unexpected behaviour.

 

 

The cross thread allocations dialog

 

To show the cross-thread allocations dialog, choose the menu option below:

 

menu Query menu instructionStep choose Find cross-thread allocations... instructionStep displays the dialog

 

Or use the following icon on the Query Toolbar.

 

toolbar-find-xthreads

 

 cross-threadd-allocations

 

There is just the one button - to start the search

 

Find instructionStep start the search and display results in the list

 

 Results include cross-thread reallocations and deallocations.

 

For larger datasets, the search can take some time.

 

 

Note that results displayed in green indicate that some (possibly all) allocations made on this callstack have been successfully deallocated.

 

 


 

Example of finding cross-thread allocations

 

Memory Validator has an example program with which to safely explore all the features available.

 

The following sequence will allocate memory in one thread and free it in another.

 

mvExample
instructionStep Handles menu instructionStep Start thread instructionStep Exit program

 

Searching for cross-thread allocations

 

The following three char[] allocations should be found, with sequential allocation request ids.

 

cross-threadd-allocations-example1

 

Expanding one of these entries shows the allocation location and the deallocation location below.

 

The various details include thread id (different for allocation and deallocation), timestamp, request id and callstack.

 

cross-threadd-allocations-example2