memory leak detection simplified
This commit is contained in:
parent
766105b201
commit
5791341996
@ -17,8 +17,7 @@ QSK_QT_PRIVATE_END
|
|||||||
#define QSK_OBJECT_INFO 0
|
#define QSK_OBJECT_INFO 0
|
||||||
|
|
||||||
#if QSK_OBJECT_INFO
|
#if QSK_OBJECT_INFO
|
||||||
#include <qhash.h>
|
#include <qset.h>
|
||||||
#include <qtimer.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline bool qskIsItem( const QObject* object )
|
static inline bool qskIsItem( const QObject* object )
|
||||||
@ -37,15 +36,6 @@ static inline bool qskIsItem( const QObject* object )
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#if QSK_OBJECT_INFO
|
|
||||||
class ObjectInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QString name;
|
|
||||||
QString className;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Counter
|
class Counter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -80,59 +70,13 @@ namespace
|
|||||||
int maximum;
|
int maximum;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if QSK_OBJECT_INFO
|
|
||||||
class InsertEvent : public QEvent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const auto type = static_cast< QEvent::Type >( QEvent::User + 1777 );
|
|
||||||
|
|
||||||
InsertEvent( const QObject* obj )
|
|
||||||
: QEvent( type )
|
|
||||||
, object( obj )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointer< const QObject > object;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class CounterData final : public QObject
|
class CounterData final : public QObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Counter counter[ 2 ];
|
Counter counter[ 2 ];
|
||||||
|
|
||||||
#if QSK_OBJECT_INFO
|
#if QSK_OBJECT_INFO
|
||||||
void insertObjectInfo( const QObject* object )
|
QSet< const QObject* > objectTable;
|
||||||
{
|
|
||||||
// object is not fully constructed here
|
|
||||||
|
|
||||||
if ( qApp && object )
|
|
||||||
qApp->postEvent( this, new InsertEvent( object ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObjectInfo( const QObject* object )
|
|
||||||
{
|
|
||||||
objectTable.remove( object );
|
|
||||||
}
|
|
||||||
|
|
||||||
QHash< const QObject*, ObjectInfo > objectTable;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
bool event( QEvent *event ) override
|
|
||||||
{
|
|
||||||
if ( event->type() == InsertEvent::type )
|
|
||||||
{
|
|
||||||
auto ev = static_cast< const InsertEvent* >( event );
|
|
||||||
if ( const QObject* obj = ev->object )
|
|
||||||
{
|
|
||||||
objectTable.insert( obj,
|
|
||||||
{ obj->objectName(), obj->metaObject()->className() } );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -226,7 +170,7 @@ void CounterHook::addObject( QObject* object )
|
|||||||
counterData->counter[ QskObjectCounter::Items ].increment();
|
counterData->counter[ QskObjectCounter::Items ].increment();
|
||||||
|
|
||||||
#if QSK_OBJECT_INFO
|
#if QSK_OBJECT_INFO
|
||||||
counterData->insertObjectInfo( object );
|
counterData->objectTable.insert( object );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +190,7 @@ void CounterHook::removeObject( QObject* object )
|
|||||||
counterData->counter[ QskObjectCounter::Items ].decrement();
|
counterData->counter[ QskObjectCounter::Items ].decrement();
|
||||||
|
|
||||||
#if QSK_OBJECT_INFO
|
#if QSK_OBJECT_INFO
|
||||||
counterData->removeObjectInfo( object );
|
counterData->objectTable.remove( object );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,12 +338,11 @@ void QskObjectCounter::debugStatistics( QDebug debug, ObjectType objectType ) co
|
|||||||
if ( !objectTable.isEmpty() )
|
if ( !objectTable.isEmpty() )
|
||||||
{
|
{
|
||||||
debug << "\n\t=== Leaks ===\n";
|
debug << "\n\t=== Leaks ===\n";
|
||||||
for ( auto it = objectTable.constBegin(); it != objectTable.constEnd(); ++it )
|
for ( const auto object : objectTable )
|
||||||
{
|
{
|
||||||
const auto& info = it.value();
|
debug << "\tClass: " << object->metaObject()->className();
|
||||||
debug << "\tClass: " << info.className;
|
if ( !object->objectName().isEmpty() )
|
||||||
if ( !info.name.isEmpty() )
|
debug << " Name: " << object->objectName();
|
||||||
debug << " Name: " << info.name;
|
|
||||||
debug << '\n';
|
debug << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user