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

Memory leak when transitioning to inverse block #12267

Closed
raytiley opened this issue Sep 1, 2015 · 3 comments
Closed

Memory leak when transitioning to inverse block #12267

raytiley opened this issue Sep 1, 2015 · 3 comments

Comments

@raytiley
Copy link
Contributor

raytiley commented Sep 1, 2015

Tried to make the reproduction as simple as possible. Basically if you have an each inside an if or an unless statement and then transition to the inverse you leak BuiltInStreamHelpers and a bunch of related morphs and DOM fragments.

Reproduction: http://output.jsbin.com/zusuno

If you do a heap snapshot you'll see when hiding the each the only thing that is cleaned up for the rendered templates is the HTMLbarsMorph. 50 of these are deleted coresponding to the 50 items in the list.

shows-leak

If you compare this to an unless statement without an inverse, much more is cleaned up when the list is removed.

zusuno 2015-09-01 14-24-02

Thanks @rwjblue for batting this one back and forth, it was a pain to reproduce.

@rwjblue
Copy link
Member

rwjblue commented Sep 1, 2015

This seems similar conceptually (but definitely not exactly the same) to the issue fixed in #11667.

@rwjblue
Copy link
Member

rwjblue commented Sep 1, 2015

I have a bead on this. Random mind dump as follows:

calling either `options.template.yield()` or `options.inverse.yield()` in `if` sets `renderState.morphToClear` to `null`
so when the `renderAndCleanup` code runs it doesn't clear
this is good generally, when rendering `template.yield()` after `template.yield()`
so if `morphToClear` was last populated by `template` and we are rendering `template` now, clobber (this is what it does now all the time)
but if `morphToclear` was last populated by `template` and we are rendering `inverse`, we need to clear before rendering

The solution is to ensure that if we are not the same template as was last yielded, we need to clear the morph before rendering. I have the fix, and am working on the tests.

@rwjblue
Copy link
Member

rwjblue commented Sep 2, 2015

tildeio/htmlbars#407 fixes this upstream

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

No branches or pull requests

3 participants