To answer that, you really need to know the Angular garbage collection. This is a really good job. But if he believes that there is a reference to the object or if something else refers to it, a memory leak may occur. You can use jQuery or any other library to create a circular reference through a DOM object.
Here is an example. http://plnkr.co/edit/nIt78S?p=preview
If you open controllers.js, you will see a jQuery $() to Angular $scope circular link:
//*** CREATING MEMORY LEAK *** $("#memory-leak").on('click', function() { console.log("[HomeController " + myInstance + "] click()"); $scope.data.counter++; });
Since the jQuery.on () method is bound to a div outside the controller, it is never freed. You can check this out:
1) Opening the console
2) Moving between the "Home" and "Data" pages. Each time you do this, note that a new instance of Home Controller is created.
3) After you have created 3 or 4 instances, click on the div that says โMemory leak testโ. You will see 3 or 4 console logs from the above code, a memory leak!
source share