-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
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