DescriptionFix Document leak from NodeFilter.
* Problem Description
When NodeIterator/TreeWalker with filter JS callback is created, the following reference chain was created:
NodeIterator -(RefPtr)-> NodeFilter -(RefPtr)-> V8NodeFilterCondition -(ScopedPersistent)-> JS callback object -> window
This caused the whole document to be leaked when NodeIterator was referenced from window.
For example, the following script created a circular reference which could not be collected.
<script> window.foobar = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, function(node) { return NodeFilter.FILTER_ACCEPT; }); </script>
* Proposal
This patch modifies the reference chain to avoid leak. The basic idea is to move the callback's whole reference chain to the V8 side.
We change the strong reference to the JS callback object held by V8NodeFilterCondition to a weak reference.
The JS callback is instead kept alive by a wrapper of NodeFilter, referenced from NodeIterator wrapper.
The new reference chain is illustrated as follows:
Blink world: NodeIterator -(RefPtr)-> NodeFilter -(RefPtr)-> V8NodeFilterCondition
^^^ ^^^ vvv(weakref)vvv
V8 world: NodeIterator wrap -(HiddenProperty)-> NodeFilter wrap -(HiddenProperty)-> JS callback obj. -> window
The new reference chain can be collected correctly, as the whole circular reference chain is visible from V8 GC.
BUG=None
Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=155425
Patch Set 1 #
Total comments: 7
Patch Set 2 : added overcollect test, passing. #Patch Set 3 : add leak test / passing #Patch Set 4 : refactor / fix createTreeWalker #Patch Set 5 : add TreeWalker leak test #
Total comments: 15
Patch Set 6 : update LayoutTests #Patch Set 7 : fix layouttests failing #Patch Set 8 : use customToV8 #Patch Set 9 : add assertions to wrap #
Total comments: 25
Patch Set 10 : introduce leak-check.js / styling fix #Patch Set 11 : update expectations #
Total comments: 11
Patch Set 12 : fixed broken selection test #Patch Set 13 : added haraken's illustration :) / styling fixes #Patch Set 14 : don't print numberOfLiveDocuments when test passed #Messages
Total messages: 21 (0 generated)
|