'Does React clean used memory for States?
Suppose that, I should store a lot of data in component's local states with useState(). Logically React uses memory to store these data. But what does happen when one component unmount? Does React clean used memory for old states in unmounting step? or JavaScript keeps all states in memory until I close tab or refresh page?
Solution 1:[1]
React does nothing with the memory.
JavaScript manages memory allocation and deallocation by his own. This is known as garbage collection
Answering your question - in most cases JS will free the memory by himself when it's needed by removing not accessible objects.
However, sometimes you can prevent JS from freeing memory. This is known as memory leaks
If component use 1MB of memory for states, React will free all 1MB of memory after unmounting?
Most of all - no. Garbage collection will start in undermine moment, somewhere in the future
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Drag13 |
