To avoid the fact that any newly created function (context) is closed above the parent area here, you just need to get rid of the anonymous function in setTimeout . So
setTimeout(self.timeoutHandler, 750);
However, even if this closure covers the context of the parent (s), any semi-decent garbage collector (like any modern browser) will notice it and free up memory after this method has been run. A very important thing that you did not mention is the browser on which you noticed the behavior. The Firefox garbage collector, for example, works .. quite unpredictable (at least for me). This will allow more and more memory to be used, and then at some point will release a huge chunk again.
To find out whatβs going on, use Firefox and look at about:memory while the script is running. There you will see where the memory goes. I would not worry if memory usage grows for a while. Look at this, if this is all your code, memory should be freed sooner or later.
jAndy source share