From ac9ab9703ff299c94dca7585d5a12ecde28931bb Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 14 Jan 2013 13:58:05 +0100 Subject: [PATCH] QtDBus: Garbage collect deleted objects now and then. Fixes performance issues in apps which register and deregister objects very frequently (like nepomukstorage). Change-Id: Ib4ce8d65868f0e26cd45f1053e4b2f4c13528cfa Reviewed-by: Thiago Macieira --- src/dbus/qdbusintegrator.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 2b3ee901a5..42e6a80670 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -2224,6 +2224,19 @@ QDBusConnectionPrivate::disconnectSignal(SignalHookHash::Iterator &it) return signalHooks.erase(it); } + +static void cleanupDeletedNodes(QDBusConnectionPrivate::ObjectTreeNode &parent) +{ + QMutableVectorIterator it(parent.children); + while (it.hasNext()) { + QDBusConnectionPrivate::ObjectTreeNode& node = it.next(); + if (node.obj == 0 && node.children.isEmpty()) + it.remove(); + else + cleanupDeletedNodes(node); + } +} + void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node) { connect(node->obj, SIGNAL(destroyed(QObject*)), SLOT(objectDestroyed(QObject*)), @@ -2247,6 +2260,10 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node) this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)), Qt::DirectConnection); } + + static int counter = 0; + if ((++counter % 20) == 0) + cleanupDeletedNodes(rootNode); } void QDBusConnectionPrivate::connectRelay(const QString &service,