16 #include <QReadWriteLock>
18 static QReadWriteLock leakLock;
21 LeakInfo() : refCount(0) {}
22 LeakInfo(
const QString &n) : name(n), refCount(1) {}
26 static QMap<ReferenceCounter*,LeakInfo> leakMap;
29 QReadLocker locker(&leakLock);
30 QList<uint64_t> logType;
34 QMap<ReferenceCounter*,LeakInfo>::iterator it = leakMap.begin();
35 for (; it != leakMap.end(); ++it)
37 if ((*it).refCount.fetchAndAddOrdered(0) == 0)
39 if ((*it).name.startsWith(
"CommandLineArg"))
41 if (!it.key()->m_logDebug)
45 logType += (cnt) ? VB_GENERAL : VB_REFCOUNT;
46 logLines += QString(
"Leaked %1 reference counted objects").arg(cnt);
48 for (it = leakMap.begin(); it != leakMap.end(); ++it)
50 if ((*it).refCount.fetchAndAddOrdered(0) == 0)
52 if ((*it).name.startsWith(
"CommandLineArg"))
54 if (!it.key()->m_logDebug)
57 logType += VB_REFCOUNT;
59 QString(
" Leaked %1(0x%2) reference count %3")
61 .arg(
reinterpret_cast<intptr_t
>(it.key()),0,16)
67 for (
uint i = 0; i < (
uint)logType.size() && i < (
uint)logLines.size(); i++)
68 LOG(logType[i], LOG_INFO, logLines[i]);
77 m_debugName(debugName),
82 QWriteLocker locker(&leakLock);
83 leakMap[
this] = LeakInfo(debugName);
91 LOG(VB_GENERAL, LOG_ERR,
92 "Object deleted with non-zero or one reference count!");
95 QWriteLocker locker(&leakLock);
96 leakMap.erase(leakMap.find(
this));
107 LOG(VB_REFCOUNT, LOG_INFO, QString(
"%1(0x%2)::IncrRef() -> %3")
108 .arg(m_debugName).arg(
reinterpret_cast<intptr_t
>(
this),0,16)
111 LOG(VB_REFCOUNT, LOG_INFO, QString(
"(0x%2)::IncrRef() -> %3")
112 .arg(
reinterpret_cast<intptr_t
>(
this),0,16).arg(val));
117 QReadLocker locker(&leakLock);
118 leakMap[
this].refCount.fetchAndAddOrdered(1);
130 QReadLocker locker(&leakLock);
131 leakMap[
this].refCount.fetchAndAddOrdered(-1);
138 LOG(VB_REFCOUNT, LOG_INFO, QString(
"%1(0x%2)::DecrRef() -> %3")
139 .arg(m_debugName).arg(
reinterpret_cast<intptr_t
>(
this),0,16)
142 LOG(VB_REFCOUNT, LOG_INFO, QString(
"(0x%2)::DecrRef() -> %3")
143 .arg(
reinterpret_cast<intptr_t
>(
this),0,16).arg(val));
147 #ifdef NO_DELETE_DEBUG
150 LOG(VB_REFCOUNT, LOG_ERR, QString(
"(0x%2)::DecrRef() -> %3 !!!")
151 .arg(
reinterpret_cast<intptr_t
>(
this),0,16).arg(val));