Whats a memory leak anyway?
In the C and C++ world, the answer is simple. Any memory that is no longer referenceable but yet not released is leaked. When you allocate memory, your application footprint grows. When you release memory, the footprint shrinks. Not so clear-cut for JavaScript. With JavaScript, you no longer have direct control of memory usage. There’s a garbage collector running in the background and it decides how and when to reclaim a piece of memory that’s no longer used. The garbage collector does so by determining which objects are no longer accessible and therefore can be deallocated from memory. It can detect circular loops among “garbage” by an algorithm called “mark and sweep”, i.e., if a group of objects hold references to each other but are nonetheless no longer referenced by anything from the active execution path of the program, they can be marked as garbage collectively and cleaned up. With JavaScript, you can have variables and object references going out of scope and yet see the memory