Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

fixed memory leak while importing html elements in IE #644

Merged
merged 5 commits into from
Nov 22, 2016

Conversation

bbsteventill
Copy link
Contributor

@bbsteventill bbsteventill commented Oct 28, 2016

541 - fixed ie memory leak when importing multiple imports

<!-- import.html -->

<link rel="import" href="/assets/paper-something/paper-something.html" />

<!-- index.html -->

<html><head></head><body>
<link rel="import" href="/import.html" />
</body></html>

this wil no longer leak in IE 11

@justinfagnani
Copy link
Contributor

@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
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

@bbsteventill bbsteventill Nov 1, 2016

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});
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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"

@justinfagnani justinfagnani merged commit 0d6b57b into webcomponents:master Nov 22, 2016
@davidmedina-contact
Copy link

This merge causes an error in IE11 for my components:

SCRIPT5007: Unable to get property 'getAttribute' of undefined or null reference
File: webcomponents-lite.min.js, Line: 64, Column: 3

var src = script.getAttribute('src');

@bbsteventill
Copy link
Contributor Author

@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

@davidmedina-contact
Copy link

davidmedina-contact commented Dec 1, 2016

@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.

@jay8t6
Copy link

jay8t6 commented Dec 6, 2016

@justinfagnani @bbsteventill when is this gonna be tagged?

@omsmith
Copy link

omsmith commented Dec 20, 2016

Seeing very big improvements in IE11 with this PR. Thanks very much @bbsteventill :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants