It is always good practice to clean up any memory leaks like timer apis
, event handlers
or any other external api which can potentially lead to any kind of memory leaks. But In case of local state, I believe there is not need to clean that manually. When the component unmounted, it's local variables are un-referenced
Garbage collector will automatically detect un-referenced memory and clean that up (using algorithms like mark-and-sweep
). There is no need to manually do that.