[webkit-qt] QtConnectionObjects not cleaned up for QtOwnership objects

tonikitoo (Antonio Gomes) tonikitoo at gmail.com
Sun Jan 17 19:42:31 PST 2010


It does not look bad to me. I'd say please file a bug, upload your
patch, and describe how to check the results.

[cc+ Kent]  Maybe kent could have an input (?)


> 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?

-- 
--Antonio Gomes


More information about the webkit-qt mailing list