story
I initially posted this, but now I'm not sure if this is what you meant:
Don't do this:
requestAnimationFrame(function () {
//a new instance of this function is created every time
})
do this: var efficientFunc = function () {
//this is created only once and is reused
requestAnimationFrame(efficientFunc);
}
requestAnimationFrame(efficientFunc);
Basically avoid writing anonymous functions for callbacks that are going to be callback-ed more than once.Another thing that might help with memory is make sure you don't keep references to things you want garbage-collected.
E.g. if object `A` has a reference to object `B`, `B`'s memory won't be freed even if you never use it again. MDN has a better explanation and example [1]
As for books I'd recommend Effective Javascript by David Herman.
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memo...