My question is to do with the issue react
has where you should not bind a function within the render
function, as this will cause a new instance of that function to be created for each render
, eventually causing the browser to run out of memory and crash.
Based on the answers I got to this question:
Create function that can pass a parameter without making a new component
It seems that if you want to pass a parameter into a function, you either have to make a new component, or essentially bind in the render
function using the arrow function ()=>
Given this, there is a trade off between creating many components to do this, or accepting that you will sometimes have to bind in the render
function.
In order to determine which option to take, I assume you would have to estimate the effect of binding in the render
function.
So I am trying to understand exactly what will happen to browser memory with too many binds in the render
function.
So my question(s) are as follows:
Am I correct in assuming that any memory used up by binding will be freed when a user refreshes the page (eg presses F5 in Chrome)? If not, when will the memory be freed up?
Then, given react
applications are single page apps, the user may never actually refresh the page - they may think they are changing page, but in fact they are always on the same page. If this is the case, is there any other point where memory will be freed up - eg if they user navigates to a different page within the react
app, will it free up the memory? The reason I ask is because if react
never frees up memory int his way, then wouldn't all react
apps eventually crash for this reason, unless a user refreshed their page?