Prevent leak from computes that have no bindings. #310

Merged
merged 1 commit into from Mar 15, 2013

Conversation

Projects
None yet
3 participants
@iamnoah
Contributor

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.

Prevent leak from computes that have no bindings.
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

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Mar 15, 2013

Contributor

very cool!

Contributor

justinbmeyer commented Mar 15, 2013

very cool!

daffl added a commit that referenced this pull request Mar 15, 2013

Merge pull request #310 from Spredfast/unbound-compute-leak
Prevent leak from computes that have no bindings.

@daffl daffl merged commit c167d44 into canjs:master Mar 15, 2013

1 check failed

default The Travis build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment