
Originally Posted by
_M_chipz
however somewhere in the QObject world there's reference to reply being connected to e_l. This remains true even if both variables are freed
No, that's not true. There is a piece of code in QObject destructor that breaks all signal-slot connections regarding the object being destroyed.
// disconnect all receivers
if (d->connectionLists) {
++d->connectionLists->inUse;
int connectionListsCount = d->connectionLists->count();
for (int signal = -1; signal < connectionListsCount; ++signal) {
QObjectPrivate::ConnectionList &connectionList =
(*d->connectionLists)[signal];
while (QObjectPrivate::Connection *c = connectionList.first) {
if (!c->receiver) {
connectionList.first = c->nextConnectionList;
delete c;
continue;
}
QMutex *m
= signalSlotLock
(c
->receiver
);
bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
if (c->receiver) {
*c->prev = c->next;
if (c->next) c->next->prev = c->prev;
}
if (needToUnlock)
m->unlockInline();
connectionList.first = c->nextConnectionList;
delete c;
}
}
if (!--d->connectionLists->inUse) {
delete d->connectionLists;
} else {
d->connectionLists->orphaned = true;
}
d->connectionLists = 0;
}
// disconnect all senders
QObjectPrivate::Connection *node = d->senders;
while (node) {
QMutex *m
= signalSlotLock
(sender
);
node->prev = &node;
bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
//the node has maybe been removed while the mutex was unlocked in relock?
if (!node || node->sender != sender) {
m->unlockInline();
continue;
}
node->receiver = 0;
QObjectConnectionListVector *senderLists = sender->d_func()->connectionLists;
if (senderLists)
senderLists->dirty = true;
node = node->next;
if (needToUnlock)
m->unlockInline();
}
// disconnect all receivers
if (d->connectionLists) {
++d->connectionLists->inUse;
int connectionListsCount = d->connectionLists->count();
for (int signal = -1; signal < connectionListsCount; ++signal) {
QObjectPrivate::ConnectionList &connectionList =
(*d->connectionLists)[signal];
while (QObjectPrivate::Connection *c = connectionList.first) {
if (!c->receiver) {
connectionList.first = c->nextConnectionList;
delete c;
continue;
}
QMutex *m = signalSlotLock(c->receiver);
bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
if (c->receiver) {
*c->prev = c->next;
if (c->next) c->next->prev = c->prev;
}
if (needToUnlock)
m->unlockInline();
connectionList.first = c->nextConnectionList;
delete c;
}
}
if (!--d->connectionLists->inUse) {
delete d->connectionLists;
} else {
d->connectionLists->orphaned = true;
}
d->connectionLists = 0;
}
// disconnect all senders
QObjectPrivate::Connection *node = d->senders;
while (node) {
QObject *sender = node->sender;
QMutex *m = signalSlotLock(sender);
node->prev = &node;
bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
//the node has maybe been removed while the mutex was unlocked in relock?
if (!node || node->sender != sender) {
m->unlockInline();
continue;
}
node->receiver = 0;
QObjectConnectionListVector *senderLists = sender->d_func()->connectionLists;
if (senderLists)
senderLists->dirty = true;
node = node->next;
if (needToUnlock)
m->unlockInline();
}
To copy to clipboard, switch view to plain text mode
My very rough test found using Qt 4.8.0 Linux x86_64 that .543K was lost per connection which was not disconnected.
How exactly did you test it?
Bookmarks