-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemoryleak.h
59 lines (50 loc) · 1.33 KB
/
memoryleak.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef _MEMORYLEAKH
#define _MEMORYLEAKH
#pragma once
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
/////////////////////////////////////////////////////////////////////////
// for debugging memory leaks type "{,,msvcr80d.dll}_crtBreakAlloc" in
// the watch window to set the allocation number at which to break
// dynamically or insert the statement "_CrtSetBreakAlloc([alloc#]);"
// at the beginning of the main() function.
/////////////////////////////////////////////////////////////////////////
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define NEW new
#endif
// memory leak finder
class FindMemoryLeaks
{
#ifdef _DEBUG
public:
FindMemoryLeaks() {}
FindMemoryLeaks(long alloc) { _CrtSetBreakAlloc(alloc); }
~FindMemoryLeaks() { _CrtDumpMemoryLeaks(); }
#endif
};
class FindMemoryLeaksExt
{
#ifdef _DEBUG
public:
FindMemoryLeaksExt()
{
_CrtMemCheckpoint(&m_checkpoint);
};
~FindMemoryLeaksExt()
{
_CrtMemState checkpoint;
_CrtMemCheckpoint(&checkpoint);
_CrtMemState diff;
if (_CrtMemDifference(&diff, &m_checkpoint, &checkpoint))
_CrtMemDumpStatistics(&diff);
//_CrtMemDumpAllObjectsSince(&diff);
};
private:
_CrtMemState m_checkpoint;
#endif
};
#endif
#endif