Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

memory-leak in ng-repeat #4026

Closed
mkurtak opened this issue Sep 17, 2013 · 8 comments
Closed

memory-leak in ng-repeat #4026

mkurtak opened this issue Sep 17, 2013 · 8 comments

Comments

@mkurtak
Copy link

mkurtak commented Sep 17, 2013

Hi,

I have found memory leak when using ng-view with ng-repeat in it. I believe it is a bug in angular 1.0.8 and 1.2.0.rc2. Here is a sample code http://plnkr.co/5adwl9kwCyxT5urU9D5x

and without directive http://plnkr.co/edit/eRuNqTaKILjIsTkWUwIn

Bug occures when switching between views:
view1 - view with directive nievents (ng-repeat inside it)
view2 - empty view

After switching between views several times, i can see Detached DOM tree (with 7529 entries) with elements from view1, although i am switched to view2. When you keep switching again and again, copies of Detached DOM trees are created and cause memory leak.

I am not able to determine what causes a memory leak, but I can see ng-repeat scopes are not destroyed (parent scopes from controller are destroyed).

Tested on Chrome 29.0.1547.66 m but FF is also leaking.

I attached screenshot of heap snapshot https://groups.google.com/forum/#!topic/angular/SZzrF1uR4OE

@bajamircea
Copy link

mkurtak, in order to identify what causes your memory leak, can you try to reduce the amount of code in your example? e.g. simplify the events.html and the dummy init data in the directive. Is all the code required to reproduce the issue?

@mkurtak
Copy link
Author

mkurtak commented Sep 19, 2013

Ok i have simplified it on: http://plnkr.co/eRuNqTaKILjIsTkWUwIn. To reproduce it click on 'view1' and 'view2' again and again. After some time i can see Detache DOM tree elements growing.
Bug occurs sooner when you have more elements with angular expressions or directives in DOM

@petebacondarwin
Copy link
Contributor

The memory usage does seem to be increasing.

@bajamircea
Copy link

@mkurtak, I can't reproduce your problem either. In Chrome I only have one Detached DOM tree, not several like in your screenshot. How did you decide that FF is also leaking?

@mkurtak
Copy link
Author

mkurtak commented Sep 19, 2013

We have created a script that keeps changing location from view1 to view2 every second and run this script in FF console. After some time FF process occupied 1,8 GB of memory.

@ghost ghost assigned IgorMinar Sep 19, 2013
@IgorMinar
Copy link
Contributor

I hammered on the test case in Chrome (30.0.1599.37 beta) and couldn't reproduce the leak.

screen shot 2013-09-19 at 3 03 03 pm

I'll try in FF...

@IgorMinar
Copy link
Contributor

I can't repro it in FF (23.0.1) even after running your reduced test case there for quite a while.

screen shot 2013-09-19 at 3 21 13 pm

I'm going to close this issue. Please reopen if you still see it and can provide a better example.

@mkurtak
Copy link
Author

mkurtak commented Sep 20, 2013

It seem you are right Igor. My fault. I didnt check that Chrome runs GC and clears Detached DOM elements after some time. Wouldn't it be better if all child scopes of $destroyed scope are also cleared (clear watchers, observers, listeners and scopes)?

I've found this code in $destroy method of scope:

// This is bogus code that works around Chrome's GC leak
// see: #1313 (comment)
this.$parent = this.$$nextSibling = this.$$prevSibling = this.$$childHead =
this.$$childTail = null;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants