Class to access forgotten objects in memory.
Inspired by Rainer Grimm and Mouaz Chamieh.
More...
#include <MemoryLeakIndicator.h>
|
struct | MemoryItem |
| Reference to the instantiated object with file name and line where it was instantiated. More...
|
|
Class to access forgotten objects in memory.
Inspired by Rainer Grimm and Mouaz Chamieh.
- See also
- https://www.grimm-jaud.de/index.php/blog/operator-new-und-delete-ueberladen und https://github.com/muazsh/MemoryLeakManager
- Author
- Helmut Jakoby
- Copyright
- © 2021 Helmut Jakoby
◆ LeakMap() [1/2]
MemSpy::LeakMap::LeakMap |
( |
| ) |
|
|
protected |
The standard constructor is not available. You can get an instance via LeakMap::create().
◆ ~LeakMap()
virtual MemSpy::LeakMap::~LeakMap |
( |
| ) |
|
|
protectedvirtual |
◆ LeakMap() [2/2]
MemSpy::LeakMap::LeakMap |
( |
const LeakMap & | | ) |
|
|
private |
The copy constructor is not available.
◆ create()
static LeakMap * MemSpy::LeakMap::create |
( |
| ) |
|
|
static |
Instantiation function. Since LeakMap is a singleton class, this method instantiates it once and then only returns the pointer to the instance.
- Returns
- The only instance of this class.
- Attention
- The delivered instance must be removed from memory with LeakMap::destroy().
◆ destroy()
static int MemSpy::LeakMap::destroy |
( |
| ) |
|
|
static |
If the calling instance is the last one with a reference to the only instance of LeakMap, this instance is removed from memory.
- Returns
- Return is the number of still-references to this instance.
◆ destroyAbsolutely()
static void MemSpy::LeakMap::destroyAbsolutely |
( |
| ) |
|
|
static |
It removes the only instance of LeakMap from memory without querying ms_iReferenceCounter.
- Attention
- This should only be done at the end of the main.
◆ getGlobalLeakMapInstance()
static LeakMap * MemSpy::LeakMap::getGlobalLeakMapInstance |
( |
| ) |
|
|
static |
◆ getSpyObject() [1/2]
MemoryItem * MemSpy::LeakMap::getSpyObject |
( |
INT_PTR | ipAddress | ) |
|
Returns a MemoryItem object from the list of MemoryItem objects which references the object with the passed address.
- Parameters
-
[in] | ipAddress | The address of the searched object cast on INT_PTR. |
- Returns
- If found the MemoryItem object, otherwise NULL_PTR.
- Attention
- The calling instance must not remove the supplied object from memory.
◆ getSpyObject() [2/2]
Returns a MemoryItem object from the list of MemoryItem objects related to eMode.
- Parameters
-
Parameter examples:
- START = get first element
- CURRENT = returns current element
- NEXT = returns next element
- Returns
- If found, the MemoryItem object, otherwise NULL_PTR.
- Attention
- The calling instance must not remove the supplied object from memory.
◆ insertSpyObject()
void MemSpy::LeakMap::insertSpyObject |
( |
void * | pNewObject, |
|
|
char const * | chFileName, |
|
|
int | iLine ) |
Inserts a MemoryItem object into the list of MemoryItem objects.
- Parameters
-
[in] | pNewObject | The pointer to the new object to be inserted. |
[in] | chFileName | The name of the file in which the new object was created. |
[in] | iLine | The line number in which the new object was created. |
◆ leakMapUseAllowed()
bool MemSpy::LeakMap::leakMapUseAllowed |
( |
| ) |
const |
◆ numberOfProcessedObjects()
unsigned long long MemSpy::LeakMap::numberOfProcessedObjects |
( |
| ) |
const |
Returns the number of objects processed so far.
- Returns
- See above.
◆ operator=()
The assignment operator is not available.
◆ removeSpyObject()
void MemSpy::LeakMap::removeSpyObject |
( |
void * | pObjectToDelete | ) |
|
Removes a MemoryItem object from the list of MemoryItem objects.
- Parameters
-
[in] | pObjectToDelete | Reference to the object to delete. |
◆ setLeakMapUseAllowed()
void MemSpy::LeakMap::setLeakMapUseAllowed |
( |
bool | bAllowed = true | ) |
|
◆ sizeOfObjectList()
std::size_t MemSpy::LeakMap::sizeOfObjectList |
( |
| ) |
const |
Retrurns the number of entries in m_ObjectList.
- Returns
- See above.
◆ m_LocalCriticalSection
CRITICAL_SECTION MemSpy::LeakMap::m_LocalCriticalSection |
|
private |
To have thread-safe access to the list of objects, access is synchronized via this local mutex.
◆ m_ObjectList
std::unordered_map< INT_PTR, MemoryItem * > MemSpy::LeakMap::m_ObjectList |
|
private |
The list of MemoryItem objects. The index is the address, cast to INT_PTR, of the individual objects.
◆ m_ObjectListIterator
std::unordered_map<INT_PTR,MemoryItem*>::iterator MemSpy::LeakMap::m_ObjectListIterator |
|
private |
An internal iterator to the MemoryItem object list.
◆ m_ullInsertCounter
unsigned long long MemSpy::LeakMap::m_ullInsertCounter |
|
private |
A counter that is incremented for each inserted object.
◆ ms_bUseLeakMap
bool MemSpy::LeakMap::ms_bUseLeakMap |
|
staticprivate |
Only if true, LeakMap is used in new (...) and delete (...). Is necessary to not recursively process own calls of new and delete here.
◆ ms_iReferenceCounter
int MemSpy::LeakMap::ms_iReferenceCounter |
|
staticprivate |
The reference counter to the only instance of this class.
The documentation for this class was generated from the following file: