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

Prevent leak from computes that have no bindings. #310

Merged
merged 1 commit into from
Mar 15, 2013

Conversation

iamnoah
Copy link
Contributor

@iamnoah iamnoah commented Mar 13, 2013

If the same event triggers an update to a compute AND
the same event also unbinds the compute, it can result in
the compute having bindings = 0, but still haveing a bound
onchanged handler.

This results in unecessary recomputes and can leak Models in
the Model store.

I know the test case seems very esoteric, but it's actually quite easy to get into this situation with live binding:

{{#if computeA}}
   {{#if computeB}}
      <span>Whatever</span>
   {{/if}}
{{/if}}

Whenever computeA = false, computeB should be unbound (since it is no longer rendered), but because the same event that unbinds computeB also triggers a recompute of B, B's onchanged handler will still be called, even though bindings === 0. It then binds normally, which causes the leak, since teardown has already been called and the original bindings context is lost.

If the same event triggers an update to a compute AND
the same event also unbinds the compute, it can result in
the compute having bindings = 0, but still haveing a bound
onchanged handler.

This results in unecessary recomputes and can leak Models in
the Model store.
@justinbmeyer
Copy link
Contributor

very cool!

daffl added a commit that referenced this pull request Mar 15, 2013
Prevent leak from computes that have no bindings.
@daffl daffl merged commit c167d44 into canjs:master Mar 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants