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

Store unsubscribe memory leak #3474

Closed
dmitrysteblyuk opened this issue Jul 12, 2019 · 0 comments
Closed

Store unsubscribe memory leak #3474

dmitrysteblyuk opened this issue Jul 12, 2019 · 0 comments

Comments

@dmitrysteblyuk
Copy link
Contributor

dmitrysteblyuk commented Jul 12, 2019

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.

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

2 participants