class RED::MemoryLeakTracker

Memory leak tracker class. More...

#include <REDMemoryLeakTracker.h>

Public classes:


Public functions:

MemoryLeakTracker ( )
~MemoryLeakTracker ( )
RED_RCDumpAllocations ( bool iPanel )
const RED::Map< const void *, RED::MemoryLeakTracker::MemInfos > &GetMemoryInformations ( ) const
size_tGetTotalAllocations ( ) const
boolIsLiveAddress ( void * iAddress ) const
voidRecordAllocInfo ( void * iAddress, size_t iSize, int iCallerID )
voidRemoveAllocInfo ( const void * iAddress )
RED_RCSetDumpFolder ( const RED::String & iDumpFolder )
voidSetUserTrackingCallback ( USER_MLT_CALLBACK iMLTCallback, void * iUserData )

Public typedefs:

typedef void(*USER_MLT_CALLBACK )(bool iOperation, const void *iAddress, size_t iSize, int iAllocationNumber, int iCallerID, void *iUserData)

Protected variables:

RED::Map< const void *, MemInfos >_meminfos
void *_mltcb_user_data
RED::Mutex *_mutex

Protected static variables:

static unsigned int_alloc_count

Detailed description:

Memory leak tracker class.

This class records all allocations that have been done using REDsdk's special allocation calls 'rnew', 'rmalloc', 'rrealloc' or 'rdelete'. Standard 'new' and 'delete' calls are also tracked, but only for all RED::Object inherited classes.

See the RED::MemoryAllocator class for details. Using these calls, the allocated memory is recorded by the memory leak tracker. All REDsdk's internal calls are going through this mechanism as well, making the memory leak tracker an efficient tool for keeping an eye over the total memory being allocated by the engine at a time.

A user can add it's own callback to be notified of each memory operation.

Functions documentation

Default constructor.


Dumps all allocations.

All allocations are dumped into a file called 'memory_report.txt' in the current application execution folder, unless specified otherwise through the REDMemoryLeakTracker::SetDumpFolder method.


iPanel:If true, dump a panel with an OK button prompt that contains a summary of all allocations. The panel is displayed in addition to the file dump.


RED_OK if the operation has succeeded,
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_FAIL if an error has occurred.

Returns all memory information.


The RED::Map used to store all currently live allocations.

Returns the current amount of allocated memory.


The total number of allocated bytes through the RED::MemoryAllocator.
public bool RED::MemoryLeakTracker::IsLiveAddress(void *iAddress) const

Tests a single address for existence.

Please note that many memory allocations of deleted objects (for instance using the RED::Factory) are not effectively released by REDsdk until a call to RED::IResourceManager::EndState has occurred.


iAddress:Address to test.


true if the address exists, false otherwise.
public void RED::MemoryLeakTracker::RecordAllocInfo(void *iAddress,

Tracks an allocation.


iAddress:Address of the allocation.
iSize:Byte size of the allocation.
iCallerID:Identifier of the allocation caller.
public void RED::MemoryLeakTracker::RemoveAllocInfo(const void *iAddress)

Removes an allocation from the storage.


iAddress:Memory address that has been released.

Defines the folder used to save the 'memory_report.txt' file.

The folder in which the dump file is saved is by default set to the current application folder. This location can be changed thanks to this method.


iDumpFolder:The complete path to the dump folder.


RED_OK if the operation has succeeded,
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_FAIL if an error has occurred.

Defines the user memory tracking method.

This lets the user be notified of every memory operation inside the engine.


iMLTCallback:The new callback. NULL to invalidate the current callback.
iUserData:The user data associated with the callback.

Variables documentation

Total memory currently allocated by our allocator.

File dump folder.

Map of the recorded memory operations.

User memory operation notification callback.

User data associated with the notification callback.

Mutex to guarantee multi-threading safety.

Used to avoid Map re-entrance in the tracker.

protected static unsigned int RED::MemoryLeakTracker::_alloc_count

Allocation counter.

Types documentation

public typedef void(* RED::MemoryLeakTracker::USER_MLT_CALLBACK)(bool iOperation, const void *iAddress, size_t iSize, int iAllocationNumber, int iCallerID, void *iUserData)

Prototype of the user memory tracking callback.

Defines the prototype of the user memory tracking callback. When the callback is set, the user is notified of each memory change that is tracked by the memory leak tracker.

Please note that the 'iAllocationNumber' that provides the number of the allocation since the program start is only reliable in non-multi threaded environments. Therefore, if the application renders using one of the engine ray-tracers with more than one single calculation thread, the allocation number may change.


iOperation:Memory operation code. true: allocation. false: release.
iAddress:Address affected by the operation.
iSize:Byte size of the operation.
iAllocationNumber:Number of the recorded allocation since the program execution start.
iCallerID:Identifier of the operation's caller.
iUserData:Custom user data get from RED::MemoryLeakTracker::SetUserTrackingCallback.