Am I right in thinking that,
With each call, test() exports another new object that must be garbage collected later.
var sumValue=test(0,3);
function test(startingValue,n){
return({sum:startingValue+n});
}
This version of test() requires no garbage collection later.
var sumValue={sum:0};
test(sumValue,3);
function test(output,n){
output.sum+=n;
}
For this specific case, I wouldn't worry about it. It's too small to make an impact (unless this code is being run multiple times for extended periods).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With