How to catch memory leaks in an Angular application?

And the answer is cache.

Heap Snapshot analysis

I don’t know what it is, but this thing grows. It seems to be related to jQuery. Maybe it’s the jQuery element cache. Do you by any chance apply a jQuery plugin on one or more elements after every service call?

Update

The problem is that HTML elements are added, processed with jQuery (e.g. via the popbox plugin), but either never removed at all or not removed with jQuery. To process in this case means stuff like adding event handlers. The entries in the cache object (whatever it is for) do only get removed if jQuery knows that the elements have been removed. That is the elements have to be removed with jQuery.

Update 2

It’s not quite clear why these entries in the cache haven’t been removed, as angular is supposed to use jQuery, when it’s included. But they have been added through the plugin mentioned in the comments and contained event handlers and data. AFAIK Antonio has changed the plugin code to unbind the event handlers and remove the data in the plugin’s destroy() method. That eventually removed the memory leak.

Leave a Comment