3

Is there a way to see unnecessary objects still in memory or pending network requests after the React component has unmounted? If I can see that then I can handle that in componentWillUnmount().

coder
  • 109
  • 4
  • for cancelling pending requests using axios, check this https://stackoverflow.com/questions/46110082/cancel-async-request-on-unmount-with-axios – Amir Saleem Apr 07 '21 at 05:23

1 Answers1

1

Amir Saleem already mentioned Axios for handling requests. I don't think, that you need to be very concerned about garbage collection in JavaScript as the language interpreter does that for you.

That is a huge difference to C/C++ or some other low level languages where you are responsible for creating and deleting unused memory space.

Just put in the time to use good, tested and efficient algorithms in your code and let the Garbage Collector do the rest. Your whole component will be garbage collected if you're no longer using it.

If you really want an overview of the objects in your application, Firefox has a Memory feature in the developer console. It looks like that:

enter image description here

See more information on Memory Management. Avoiding Memory Leaks in NodeJS might also be interesting for you. Please see also the references on the bottom of the last page.

Felix
  • 2,531
  • 14
  • 25