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

Removing calls to setState after unmount (#139) #140

Closed

Conversation

stevenwcarter
Copy link

Issue #139 was the same issue I was having when resizing a window.
I was receiving an error about a possible memory leak since setState
was called on an unmounted component. It seems like the getMatches
call was taking just long enough that the component could be unmounted
while it was executing. By using a _mounted flag, we can determine
if it is safe to call setState and bypass it if the component is
unmounted. I looked at using an abort signal, but I don't think the
matchMedia API is robust enough for that currently.

Issue ReactTraining#139 was the same issue I was having when resizing a window.
I was receiving an error about a possible memory leak since setState
was called on an unmounted component. It seems like the `getMatches`
call was taking just long enough that the component could be unmounted
while it was executing. By using a `_mounted` flag, we can determine
if it is safe to call `setState` and bypass it if the component is
unmounted. I looked at using an abort signal, but I don't think the
`matchMedia` API is robust enough for that currently.
@stevenwcarter
Copy link
Author

Let me know if you prefer this to be created against the next branch and I will update accordingly.

@stevenwcarter
Copy link
Author

Closing as this doesn't address the underlying issue (the listeners aren't being canceled). This is just preventing the setState call.

@stevenwcarter stevenwcarter deleted the mounted-check-patch branch November 21, 2019 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant