question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useSelector results memory leak in child component

See original GitHub issue

using this in parent component and back-forth to page, left memory uncleaned. without useselector issue is fixed.: Screen Shot 2020-06-28 at 14 54 42 Screen Shot 2020-06-28 at 14 54 37

export function RegisterScreenFooter () {

    let footerState = useSelector((state: registration) => state.registration.footer);

https://stackoverflow.com/questions/62622168/useselector-results-memory-leak-in-child-component

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
markeriksoncommented, Jan 31, 2021

Yes, this.unsubscribe() is the right line.

A Subscription instance will be subscribed to either the Redux store directly, or its nearest Subscription ancestor. So, per these lines, this.unsubscribe is the subscription cleanup function that was either returned from store.subscribe(), or parentSub.addNestedSub():

https://github.com/reduxjs/react-redux/blob/a9235530f4799dd4b2acb3cc65e9caf32efbc44b/src/utils/Subscription.js#L105-L107

0reactions
phryneascommented, Oct 10, 2022

@LaxmanPache123 you should be doing const permissions = useSelector((state) => { return state.user.permissions; }); but either way that will just lead to more rerenders, not to a memory leak. It is highly unlikely that that line is causing any kind of leak, but if it does: please read the comment above yours.

Without any reproduction (a runnable repository where we can see it happening) we cannot do anything about this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cleanup memory leaks on an Unmounted Component in ...
This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a...
Read more >
How to fix the React memory leak warning - DEV Community ‍ ‍
This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a...
Read more >
[Solved]-Can a Redux store lead to a memory leak?-Reactjs
Assuming you are following the recommended approaches for updating data, old data references are discarded and will be garbage-collected. Redux itself does not ......
Read more >
How to connect Redux Store components with useSelector ...
We've broken down the best practices on how to properly connect all functional components to the Redux Store with the help of useSelector...
Read more >
React state update on an unmounted component - debuggr.io
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found