-
Notifications
You must be signed in to change notification settings - Fork 491
fixed memory leak while importing html elements in IE #644
fixed memory leak while importing html elements in IE #644
Conversation
08529e2
to
6d8fe16
Compare
@bbsteventill can you give a brief description of the fix and why it prevents the memory leak? |
var observer = node.__observer; | ||
|
||
// this needs to be on head or it will leak in IE | ||
// IE does not like it when you have non-standard attributes on root dom's, so put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What non-standard attribute is on the root dom, and what's the "root dom"? A document? If so, that answers my next question, which is how do we know the node has a head
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do we need node.head && node.head.__observer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 250 says node
will be either a document or ShadowRoot. ShadowRoot won't have a head
, do we have test coverage on this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My findings are attributes that are not defined in the w3 spec. I found an example that will cause a leak as part of the UrlResolver in polymer where a 'a' element is being appended to the root document, this will cause a memory leak, but if you set the baseURI that does NOT cause a memory leak. I think it is because baseURI is defined in the w3 spec while __url is not (https://github.com/Polymer/polymer/pull/3964/files)
Note: the easiest way to test this is to create a iron-image that does not have a valid url as its source - it should start to leak in ie because of the .__url not being on the head element.
a root dom, is any root document that has been created with document.implementation.createHTMLDocument
this is why we need the node.head && node.head.__observer, because placing the observer directly on the node (this is where the code is poorly named because node is always a root shadow document at this point in the code)
we do have test coverage of this, the tests will break if you remove the createElement('head') && createElement('body) that was added Element.js
var observer = new MutationObserver(handler.bind(this, inRoot)); | ||
observer.observe(inRoot, {childList: true, subtree: true}); | ||
inRoot.__observer = observer; | ||
observer.observe(inRoot.head, {childList: true, subtree: true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're observing both head and body, why not just observe the whole document?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that my friend is what will causes a memory leak in IE; which is what it was before
@@ -74,7 +74,9 @@ var importer = { | |||
// generate an HTMLDocument from data | |||
doc = err ? null : makeDocument(resource, redirectedUrl || url); | |||
if (doc) { | |||
doc.__importLink = elt; | |||
// IE will leak if you put the node directly on the shadow dom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by "shadow dom" do you mean ShadowRoot? Which variable here is a ShadowRoot? Maybe this should say "Document"
fd00c30
to
e2d563a
Compare
This merge causes an error in IE11 for my components: SCRIPT5007: Unable to get property 'getAttribute' of undefined or null reference
|
@jdmedina More information is required; first do not use your own custom minified version of the script. Second I know that the debugger in IE does different things then what happens in chrome; for example when you try to view properties on a prototype I think the IE debugger evaluates the properties for you; this may be bad because things like script.getAttribute('src'), your script object may be null |
@bbsteventill By custom you mean the lite version (sans shady dom)? Even though IE was saying the error is on that minified file, I was not using that minified file. I am using Fiddler to hot-swap the file we're using in our test server with the a version of webcomponents-lite.js in the master locally. Even with the debugger off, the components break on my page and don't work. Let me know what other type of extra info you need. |
@justinfagnani @bbsteventill when is this gonna be tagged? |
Seeing very big improvements in IE11 with this PR. Thanks very much @bbsteventill :) |
541 - fixed ie memory leak when importing multiple imports
this wil no longer leak in IE 11