Skip to main content


Showing posts from March, 2017

Avoiding Memory Leaks:
A peek in Browsers' Closure's Optimization

In this post, I want to cover a Closure optimization meant to help us preventing memory leaks. This optimization is implemented by the three major browsers: Chrome, Firefox and IE. Closure is a popular subject and you can find very good articles out there . Although the post won't cover Closures internals, I will briefly cover the basics in order to keep the reading fluent. Basics To put it shortly; any time we access a method in JS, a special context object is created. This object contains the variables to be searched in the scope chain search process. var x = 10; (function parentFunc () { console.log(x); }()); //* Result: 10 The code above will print 10 because when the parentFunc method is executed, a special context object containing its parent's variables is created and is pointed by parentFunc method scope. When the interpreter starts searching for 'x' value it searches inside the parentFunc scope. If it can not find it, its parent scope gets eva