Skip to content

Subscription leak when using live flag with observableArray #674

Description

@SimmeNilsson

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions