I have two methods below:
function foobar() {
const viewState = getViewState();
return () => { use(viewState); }
}
function foobar() {
return (viewState) => { use(viewState); }
}
Can you please let me know if there is memory leak from any of these functions?
I was told by someone that the 1st method is leaking since the viewState is passed from outside and it is being held inside the closure without being released, whereas the 2nd function is not leaking because viewState is passed as a parameter.
If that's true, I am interested in more detailed explanation.