-
Notifications
You must be signed in to change notification settings - Fork 49.8k
Description
Do you want to request a feature or report a bug?
Bug (or misunderstanding on my part)
What is the current behavior?
Fibers seem to retain stale references to old data via memoizedProps / memoizedState
Demo:
https://jsfiddle.net/0tfq4p5r/
This demo just puts some big strings in the state (and into the props of a child component). If you click the button it will replace the array of strings with an empty array. At this point if you inspect the memory usage you will see that both memoizedState and memoizedProps are still holding references to the original array of strings and that memory can't be collected.
What is the expected behavior?
I was expecting no references to the old data to be retained, so that the memory could be reclaimed immediately.
I ran into this when testing an app with a large dataset that is near my browser's heap limit. If I want to replace that with a different, equally large dataset, and I attempt to make the first large dataset GC-able by removing it from my Redux store before putting the second dataset in the store, I wind up with the old dataset still resident in memory due to being retained by memoizedProps of a fiber.
I noticed this PR that sounds possibly related:
and tested against current master (f1bf281) but still had the issue with memoizedProps.
Right now I'm working around this by clearing the props twice consecutively before loading the new data. Is that the intended solution for this situation?
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
macOS High Sierra 10.13.6 (17G65)
Chrome Version 70.0.3538.110 (Official Build) (64-bit)
React 16.6.3
Don't know about previous versions of React.