Understanding AngularJS and Google Chrome memory management Understanding AngularJS and Google Chrome memory management google-chrome google-chrome

Understanding AngularJS and Google Chrome memory management


I'm doing a similar thing now. What I've noticed is a couple of things:1) look at any usage of $(window).fn() -- where fn is any of the functions on the window object; if you're doing that more than once you're adding multiple event handlers to the global object which causes a memory leak

2) $rootScope.$watch() -- similarly, if you're doing this more than once (say, when loading a directive) then you're adding multiple handlers to the global object

3) In my tests (where I go back and forth between two pages) it seems that chrome consumes a large amount of memory (in my case, almost 1GB) before garbage collection kicks in. Maybe when you click the "garbage collection" chrome is not actually doing a GC? Or it's GC for javacsript but not for dom elements?

4) If you add an event handler to the dom element, then remove it from the dom, the handlers never get GC'ed.