16 #include <QReadWriteLock>
18 #include "../libmythui/mythimage.h"
19 static QReadWriteLock leakLock;
22 LeakInfo() : refCount(0) {}
23 LeakInfo(
const QString &n) : name(n), refCount(1) {}
27 static QMap<ReferenceCounter*,LeakInfo> leakMap;
30 QReadLocker locker(&leakLock);
31 QList<uint64_t> logType;
35 QMap<ReferenceCounter*,LeakInfo>::iterator it = leakMap.begin();
36 for (; it != leakMap.end(); ++it)
38 if ((*it).refCount.fetchAndAddOrdered(0) == 0)
40 if ((*it).name.startsWith(
"CommandLineArg"))
42 if (!it.key()->m_logDebug)
46 logType += (cnt) ? VB_GENERAL : VB_REFCOUNT;
47 logLines += QString(
"Leaked %1 reference counted objects").arg(cnt);
49 for (it = leakMap.begin(); it != leakMap.end(); ++it)
51 if ((*it).refCount.fetchAndAddOrdered(0) == 0)
53 if ((*it).name.startsWith(
"CommandLineArg"))
55 if (!it.key()->m_logDebug)
58 logType += VB_REFCOUNT;
60 QString(
" Leaked %1(0x%2) reference count %3")
62 .arg(
reinterpret_cast<intptr_t
>(it.key()),0,16)
68 for (
uint i = 0; i < (
uint)logType.size() && i < (
uint)logLines.size(); i++)
69 LOG(logType[i], LOG_INFO, logLines[i]);
77 m_debugName(debugName),
83 QWriteLocker locker(&leakLock);
84 leakMap[
this] = LeakInfo(debugName);
92 LOG(VB_GENERAL, LOG_ERR,
93 "Object deleted with non-zero or one reference count!");
96 QWriteLocker locker(&leakLock);
97 leakMap.erase(leakMap.find(
this));
108 LOG(VB_REFCOUNT, LOG_INFO, QString(
"%1(0x%2)::IncrRef() -> %3")
109 .arg(m_debugName).arg(
reinterpret_cast<intptr_t
>(
this),0,16)
112 LOG(VB_REFCOUNT, LOG_INFO, QString(
"(0x%2)::IncrRef() -> %3")
113 .arg(
reinterpret_cast<intptr_t
>(
this),0,16).arg(val));
118 QReadLocker locker(&leakLock);
119 leakMap[
this].refCount.fetchAndAddOrdered(1);
131 QReadLocker locker(&leakLock);
132 leakMap[
this].refCount.fetchAndAddOrdered(-1);
139 LOG(VB_REFCOUNT, LOG_INFO, QString(
"%1(0x%2)::DecrRef() -> %3")
140 .arg(m_debugName).arg(
reinterpret_cast<intptr_t
>(
this),0,16)
143 LOG(VB_REFCOUNT, LOG_INFO, QString(
"(0x%2)::DecrRef() -> %3")
144 .arg(
reinterpret_cast<intptr_t
>(
this),0,16).arg(val));
148 #ifdef NO_DELETE_DEBUG
151 LOG(VB_REFCOUNT, LOG_ERR, QString(
"(0x%2)::DecrRef() -> %3 !!!")
152 .arg(
reinterpret_cast<intptr_t
>(
this),0,16).arg(val));