Skip to content

Store unsubscribe memory leak #3474

Closed
Closed
@dmitrysteblyuk

Description

@dmitrysteblyuk

Do you want to request a feature or report a bug?
Report a bug

(If this is a usage question, please do not post it here—post it on Stack Overflow instead. If this is not a “feature” or a “bug”, or the phrase “How do I...?” applies, then it's probably a usage question.)

What is the current behavior?
References to listeners are not removed internally on unsubscribe which leads to memory leaks.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.
Consider the following example:

import {createStore} from 'redux';

const store = createStore((state = {}) => state);

class MyTestClass {
  run() {
    console.log('Done.');
  }
}

runTest();

function runTest() {
  const test = new MyTestClass();
  const unsubscribe = store.subscribe(() => {
    test.run();
  });
  store.dispatch({type: 'RUN'});
  unsubscribe();
}

// won't be called but will keep code running
setInterval(runTest, 10000000000);

Once runTest function is called I expect there'll be no references to test object left because I unsubscribe from the store. But in reality I can still see one instance of MyTestClass in memory heap snapshot.

What is the expected behavior?
All references to a passed to subscribe listener are removed on unsubscribe.

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
4.0.4. Win/Mac, Google Chrome.
Doesn't work in 3.6.0 either.

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