Garbage collection

JavaScript is a garbage collected language. What that means is that a JavaScript engine will occasionally fire something called a garbage collector, which looks for unused and inaccessible references in memory for the program and clears them, making the memory available for storing other data.

Garbage collectors make life a lot easier, but add a bit of overhead in performance-critical applications. Say you are coding a 3D game where you want very high Frames Per Second (FPS) on not so good hardware.

You might see that the results are extremely good for a game coded in C/C++, as compared to a garbage collected language like Java. This is because when you're playing the game, garbage collectors might fire off even when it ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.