ScriptInterpreter cache for domobjects (dangerous change?)

David Faure dfaure@klaralvdalens-datakonsult.se
Fri, 10 Jan 2003 00:47:37 +0100


=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 09 January 2003 23:02, Maciej Stachowiak wrote:
> I can explain this change. DOMNode is a subclass of KJS::ObjectImp,=20
> which means it's a garbage-collected object. The ScriptInterpreter used=20
> to mark all objects it had cached, which means that the DOMNode could=20
> never be collected while the ScriptInterpreter had it cached. So=20
> effectively this code was a no-op, because the destructor could only be=20
> called once the ScriptInterpreter holding on to the node had already=20
> forgotten it.=20

Ouch. I never realized this. You're absolutely right...

> The result was that JavaScript DOM objects would be kept=20
> around until you destroy the ScriptInterpreter. In the case of Safari,=20
> this means until you close the window. I'm not sure if it has the same=20
> effect in Konqueror.

Sounds valid for Konqueror too.
(Although now it also clears this cache when going to another URL:
ScriptInterpreter::clear() is called by KJSProxyImpl::clear() - which sounds
like a fix you should merge into safari :) )

> In any case, the new code makes sure the object wrappers are kept alive=20
> by the ScriptInterpreter until the document is destroyed.
Yes - my question is, what happens if the DOM::Node behind the (KJS::DOMNod=
e)
object wrapper gets deleted.... Ah! I guess it just can't get deleted, since
KJS::DOMNode keeps a counted reference to DOM::Node.
Hmm, I guess this solves it then.

> So I am confident this change, along with the per-document object=20
> caching, will not result in dangling pointers, and plugs an important=20
> sort-of leak. It's not a true leak, since there are still live pointers=20
> to the JS DOM objects, but they are not going to be used, and=20
> accumulate until you close the window.
>=20
> Does that help?

A lot. Thanks.

Now the whole domObjectPerDocument stuff also makes sense to me :)

=2D --=20
David Faure -- faure@kde.org, dfaure@klaralvdalens-datakonsult.se
Klar=E4lvdalens Datakonsult AB, Platform-independent software solutions
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
KOffice-1.2.1 is available - http://download.kde.org/stable/koffice-1.2.1/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD4DBQE+HgoZ72KcVAmwbhARAvTSAJ9e7s6yuS7/66tYupduYStPYYzYFgCVHSzo
AF27jih1LRmnCd7dmoSCLw=3D=3D
=3Dxq/V
=2D----END PGP SIGNATURE-----