Knockout-Validation icon indicating copy to clipboard operation
Knockout-Validation copied to clipboard

Subscription leak when using live flag with observableArray

Open SimmeNilsson opened this issue 3 years ago • 0 comments

Sorry, I misunderstood the code. The inverted flag seems correct. The question is actually how can I eventually get rid of the observableArray subscriptions made by a ko.validation.group using live: true in config when I'm done with the validation group?

Thinking perhaps add/wrap (depending on observable flag) dispose on the result returned from ko.validation.group to include a cleanUpSubscriptions?

Old post

In traverseGraph there is this piece of code: if (context.options.live && utils.isObservableArray(obj)) { context.subscriptions.push(obj.subscribe(function () { context.graphMonitor.valueHasMutated(); })); }

That is the only place I can find that subscriptions array is being added to.

But when time comes for disposal the code looks like this: if (!context.options.live) { cleanUpSubscriptions(context); }

Should the check against live flag really be inverted? It will cause dispose to skip cleaning up subscriptions for the cases where there might actually be some subscriptions according to my test.

Example code https://github.com/SimmeNilsson/KnockoutValidationDisposeFix Added console.log for these parts in the code. knockout.validation.fixed.js has the inverting removed.

SimmeNilsson avatar Feb 03 '21 10:02 SimmeNilsson