[webkit-qt] QtConnectionObjects not cleaned up for QtOwnership objects
Andrew Webster
apwebster at gmail.com
Tue Dec 15 14:29:58 PST 2009
A repost from webkit-dev:
For all the Qt people out there, here is my problem:
We have quite a few QObjects that we are inserting into JavaScript
using addToJavaScriptWindowObject, however because we have limited
resources and are creating so many of these objects, we would prefer
that they are NOT ScriptOwnership objects so that there is not as much
duplication for each frame. This presents a problem when it comes to
using 'connect' to handle signals. Each connect creates a
QtConnectionObject which references the JSHTMLDocument object. The
QtConnectionObject is never destroyed because the QObject is never
destroyed, and this prevents most of the objects from being cleaned up
by the gc when the page is refreshed leading to a significant memory
leak.
The solution I'm working on essentially makes the QtConnectionObject
'script owned' so that it is cleaned up when the script is destroyed:
Index: qt_runtime.cpp
===================================================================
--- qt_runtime.cpp (revision 52150)
+++ qt_runtime.cpp (working copy)
@@ -1527,6 +1527,11 @@
else {
// Store connection
connections.insert(sender, conn);
+ // also create a script wrapper for the
connection object, but make sure that it is destroyed when
+ // the script goes away
+ d->m_instance->rootObject()->gcProtect(
+ QtInstance::getQtInstance(conn,
d->m_instance->rootObject(), QScriptEngine::ScriptOwnership)->
+
createRuntimeObject(exec->dynamicGlobalObject()->globalExec()));
}
} else {
// Now to find our previous connection object. Hmm.
This seems to be working in my limited tests. Can anyone comment on
the validity of this solution?
Thanks,
Andrew
More information about the webkit-qt
mailing list