4

I'm using angular 1.2.6, and got memory leak issue when switching the views which managed by Angular.

The DOM look like not released when view is switched.

I did a very deeply researching how to resolve memory leak in angular, but the problem is still happened.

You can see the 'detached DOM' by using profile tool of Chrome.

A very simple application here: http://myclients.azurewebsites.net/#/

Also got this issue?

You can refer this question asked by Alex Shnayder: http://www.marshut.com/iknntu/leaking-scope-when-method-on-scope-references-scope-itself.html

It's exactly the same issue with me.

cuong
  • 49
  • 1
  • 3
  • 2
    You can try to ask on github how to solve it, maybe that's a bug https://github.com/angular/angular.js/issues – jcubic Jul 04 '14 at 19:36
  • have you tried to destroy scope before the $routeChangeStart ? – Narek Mamikonyan Jul 17 '14 at 07:33
  • doesn't belong here, file a bug with angularjs and include a screenshot and the dump of the memory usage and memory leak. –  Jul 31 '14 at 03:09
  • [You could see another answer here too](http://stackoverflow.com/questions/20654684/how-to-catch-memory-leaks-in-an-angular-application/25509665#25509665) – jmbmage Aug 26 '14 at 15:30

1 Answers1

0

When trying to resolve any memory issues and deep in the trenches I sometimes look for any oddities and try studying them and rule out one by one. Here is something which may not be a problem but seems odd. I have recently asked one of my colleague to clean up these things just because I did not want the modules to be global variables.

In your app.js

//app.js
var myclients = myclients || {};
myclients.app = angular.module("myclients", ["ngRoute", "upidamodule"]);

var myclients make a global variable. Normally all modules and apps objects are encapsulated inside the angular.

I am not saying that this is the cause of the problem but I am thinking that a GC analyzer that looks for unresolved references somehow has now 2 paths. One is via the angular object itself and the second is from window object because of the var myclients.

Now the objects that you talk about including $scope, $parent etc and the includes etc they must be encapsulated in the module/app and are holding the references there.

This much be a problematic situation for the GC in Chrome - I am no expert of Chrome - just speculating.

I suggest you try this option. Among other things checkout jQuery and listener issues

bhantol
  • 9,368
  • 7
  • 44
  • 81