SteveSanderson / knockout-projections

Knockout.js observable arrays get smarter
160 stars 40 forks source link

Chained calls might result in leaks #28

Open wgebczyk opened 9 years ago

wgebczyk commented 9 years ago

When using chained calls arr.filter(...).map(...) and disposing only last chain object it might leak memory. Solution is to intercept each call in chain and "dispose" them.

ghost commented 8 years ago

Can you elaborate on this solution? Do you mean it as a workaround or something that could become a pull request?

ghost commented 8 years ago

bump

cryo-warden commented 8 years ago

Leaks are a common problem with computed observables whose computation-functions read longer-lived observables. I'm not surprised this is also an issue with what are essentially computed arrays.

To eliminate leaks:

These steps are needed only because JavaScript lacks weak references. (JavaScript is getting WeakMap, but that's different from a weak reference. WeakMap cannot fix this kind of problem.)

cryo-warden commented 8 years ago

@wgebczyk Noting what I said above about the two ways to avoid leaking memory with computed observables, your only option to prevent leaks with chained calls is to create these chained arrays as pure-computed (since you cannot call their dispose methods). I do not know if this is already a feature of this plugin. If not, then "pure-computed array projection" is the feature you should request.

JasonKleban commented 8 years ago

Thanks! (from MrAndMrsK)