DEV Community

Discussion on: Memory Leaks, How to avoid them in a React App.

Collapse
 
framitdavid profile image
David Øvrelid • Edited

First of all thanks for sharing. 👏

But I do not understand how your example is providing memory leak while setting the company after the component itself is unmounted.

Where in the memory will the variable company be stored when the component is unmounted? Would the company variable have any references at all? If not I believe the garbage collector is going to collect it?

Can you please explain why and how your example is providing the leak? 🤔

I would understand the memory leak if you had a setInterval or was subscribing to streams like WebSockets. But within your case where you have promise which resolve once, I believe the GC collects it.

Thanks in advance! :)