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

Subscription leak when using live flag with observableArray #674

Open
SimmeNilsson opened this issue Feb 3, 2021 · 0 comments
Open

Subscription leak when using live flag with observableArray #674

SimmeNilsson opened this issue Feb 3, 2021 · 0 comments

Comments

@SimmeNilsson
Copy link
Contributor

SimmeNilsson commented Feb 3, 2021

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.

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

No branches or pull requests

1 participant