blob: 2f43562bb4b3c6b0601003fe48edf37206dd62be (
plain)
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
|
// $Id$
#ifndef MLD_H
#define MLD_H
#include "ace/Synch.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "ace/Singleton.h"
#include "ace/Atomic_Op.h"
/*
This is a cheap memory leak detector. Each class I want to watch over
contains an mld object. The mld object's ctor increments a global counter
while the dtor decrements it. If the counter is non-zero when the program
is ready to exit then there may be a leak.
*/
class mld
{
public:
mld (void);
~mld (void);
static int value (void);
protected:
static ACE_Atomic_Op < ACE_Mutex, int >counter_;
};
// ================================================
/*
Just drop 'MLD' anywhere in your class definition to get cheap memory leak
detection for your class.
*/
#define MLD mld mld_
/*
Use 'MLD_COUNTER' in main() to see if things are OK.
*/
#define MLD_COUNTER mld::value()
// ================================================
#endif
|