Introducing the closure
Here is another piece of code. Instead of appending the script inline, we attach it externally:
If you don't know what a closure is, there are very good references on the web where you may find it. Closures are very useful patterns; you should learn them and keep them in your knowledge base.
And here is the graph that shows the memory leak. This is somewhat
different from the former examples. The anonymous function assigned to
To generate leak in the above scenario, we should click the button, refresh the page, click the button again, refresh the page and so on.
Clicking the button without a subsequent refresh will generate the leak
only once. Because, at each click, the