Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Templatizer leaks instance <template> element and its dataHost onto prototype #5096

Closed
kevinpschaaf opened this issue Feb 6, 2018 · 3 comments
Assignees
Labels

Comments

@kevinpschaaf
Copy link
Member

Description

The first time a template is "templatized", the reference to the <template> element instance is stored on the Templatized constructor's prototype, which is cached on the cached template content for any nested templates. This causes a leak not only of the template, but its dataHost reference, inadvertently causing a leak of potentially expensive elements all the way up the tree. The assumption is that once an element is detached and gc'ed, all dataHost references back up the tree to it are also gc'ed. This leak via the <template> element prevents proper gc from occurring.

Live Demo

http://jsbin.com/remilab/edit?html,console,output

Steps to Reproduce

Open jsBin

Expected Results

No reference to the template's dataHost is retained

Actual Results

After being removed, the instance element is retained via

    Polymer
      .telemetry
      .registrations
      .slice(-1)[0]
      ._notes[0]
      .templateContent
      ._ctor
      .prototype
      ._template
      .dataHost

Browsers Affected

All

Versions

  • Polymer: v1.x
@kevinpschaaf
Copy link
Member Author

kevinpschaaf commented Feb 6, 2018

The offending line looks to be here:

archetype._template = template;

2.x does not appear to suffer from the same leak, as the <template> instance is stored on a subclass of the cached Templatized constructor each call to templatize, rather than the cached one directly:

// Subclass base class and add reference for this specific template
/** @private */
let klass = class TemplateInstance extends baseClass {};
klass.prototype._methodHost = findMethodHost(template);
klass.prototype.__dataHost = template;

@TimvdLippe
Copy link
Contributor

@kevinpschaaf I have updated your links to use permalinks to prevent linkrot and have nice in-lining of the corresponding source code

@TimvdLippe
Copy link
Contributor

This has been fixed in #5102

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

No branches or pull requests

2 participants