Qt4-preview-feedback Archive, February 2008
Problems with deferred deletion of objects in 4.4 beta
Message 1 in thread
We're seeing significant memory leaks with 4.4 beta, and I
think I've found the reason why.
The change to note is in:
QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags
flags)
In the first few lines, I see this:
QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
But in 4.3, I see this:
QCoreApplicationPrivate::sendPostedEvents(0, (flags &
QEventLoop::DeferredDeletion) ? -1 : 0, d->threadData);
The effect of this is to ignore the DeferredDeletion flag.
Down in QCoreApplicationPrivate::sendPostedEvents(), there's
a comment in beta 4.4:
void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int
event_type,
QThreadData *data)
{
if (event_type == -1) {
// we were called by an obsolete event dispatcher.
event_type = 0;
}
...
}
But in 4.3, I see this:
void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int
event_type,
QThreadData *data)
{
bool doDeferredDeletion = (event_type == QEvent::DeferredDelete);
if (event_type == -1) {
// we were called by the event dispatcher.
doDeferredDeletion = true;
event_type = 0;
}
...
}
Does this mean we no longer need to clean up when our application shuts
down by calling qApp->processEvents(QEventLoop::DeferredDeletion)? If
so,
why are we getting so many leaked objects with 4.4 beta? Shouldn't they
get cleaned up automatically if they've been flagged for deferred
deletion?
Thanks,
Joe Newman
Synopsys, Inc.
To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx
Message 2 in thread
Joe Newman wrote:
> We're seeing significant memory leaks with 4.4 beta, and I
> think I've found the reason why.
[snip]
>
> Does this mean we no longer need to clean up when our application shuts
> down by calling qApp->processEvents(QEventLoop::DeferredDeletion)?
DeferredDelete event handling has been improved to the point where most manual
deliver of such events is unnecessary[1]. As such, the DeferredDeletion
processEvents() flag has been deprecated and doesn't work anymore in 4.4. In
addition, it's just another way of calling sendPostedEvents(0,
QEvent::DeferredDelete); However, a gratuitous change like that isn't
necessarily a good thing. I'll fix it so that the flag continues to work.
[1] However, if you call deleteLater() on many objects after the event loop
has been stopped, it's still necessary to manual clean them up (as you
apparently do).
> If so, why are we getting so many leaked objects with 4.4 beta? Shouldn't they
> get cleaned up automatically if they've been flagged for deferred
> deletion?
If you replace qApp->processEvents(QEventLoop::DeferredDeletion) with
QApplication::sendPostedEvents(0, QEvent::DeferredDelete), does the leak go
away? If so, my revert of the QEventLoop::DeferredDeletion crippling will fix
your problem.
--
[ signature omitted ]