The state in my React component does not get garbage collected when the component is dismounted, causing memory leak. I am using [email protected] on Chrome 10.12.5 on macOS Sierra.
I am setting a state in componentDidMount
like this.
To confirm the memory leak, I have added the following to my componentDidMount
:
let arr = new Uint8Array(1024 * 1024 * 30);
this.setState({
test: arr
});
and took a heap snapshot to confirm 30MB of Uint8Array allocated on heap.
Then, I have confirmed that the component gets dismounted by console.log
in componentWillUnmount
.
When I take a heap snapshot afterwards, even after allowing ample time for garbage collection to happen, Uint8Array remains in the heap.
Any ideas about where to start debugging this issue? Or any observation from the source code?
window.addEventListener
. Are you also removing that event listener? That could cause memory leaks. I just glanced at your problem so I apologize if i'm totally off there. – Rico Kahler