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

Querying a view holds the resultset in memory until you perform another query on the same view #8589

Open
KaoSDlanor opened this issue Jan 26, 2023 · 0 comments · May be fixed by #8590
Open

Comments

@KaoSDlanor
Copy link

Issue

The pouchdb-abstract-mapreduce module is keeping a reference to data that should be garbage collected which results in much higher memory usage depending on how many views you define in your application

The module defines the persistentQueues object which stores instances of the TaskQueue class.
When a view is queued to be updated or a view is queried it ensures there is a TaskQueue instance for that view and uses it to ensure that the view only has a single operation running at any time

The TaskQueue class stores a promise and whenever a new operation is added it replaces the promise with a new one

add(promiseFactory) {
  this.promise = this.promise.catch(function () {
    // just recover
  }).then(function () {
    return promiseFactory();
  });
  return this.promise;
}

The new promise retains the return value of promiseFactory() which keeps it in memory until add() is called again

If you updated the finish() method from

finish() {
  return this.promise;
}

to

finish() {
  const output = this.promise;
  this.promise = this.promise.then(() => {});
  return output;
}

Then calling finish() would release the memory

Unfortunately you would still have to update the codebase to ensure that TaskQueue.finish() is always called when you have queued all the tasks and want to get the return value

Info

  • Environment: browser
  • Platform: Chrome
  • Adapter: idb
  • Server: None (exclusively local data)

Reproduce

  • Create a design document which has a view
  • Query the view
  • Drop the return value
  • Take a heap snapshot in the memory inspector of Chrome developer tools
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

Successfully merging a pull request may close this issue.

1 participant