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

Memory leak with nested ng-repeats #2624

Closed
@ashaffer

Description

@ashaffer

This bug is a little strange, and i'm not sure whether angular is to blame or V8. I think ultimately its V8's issue, but there may or may not be things angular can do to mitigate it.

I've created a plunkr to demonstrate:

http://plnkr.co/edit/0xtIMLnl08h5BjGVDNug?p=preview

Let it run through its changes (should take only a few seconds), and then take a heap snapshot. Search for the 'Child' constructor and you should find that there are substantially more objects hanging around than there should be.

If you expand the Child objects list you should see most of them highlighted in yellow and some not highlighted at all - the un-highlighted ones are the ones that have been $destroy'd but are for some reason still resident in memory. You can check this by hovering over one and noting that $$destroyed is set to true on all of them. Note in their retention trees the reference to 'prototype' inside of $new. I can eliminate all of the references in their retention trees without modifications to angular except this one.

I have written a quasi-fix for this that is commented out currently in the plunkr. If you comment back in my replacement for $new (at the top of the file) and let it run again, then you should see that something similar happens, but hopefully with somewhat fewer extraneous scopes hanging around. However, for the few that are left, if you examine their retention trees they will be empty, which leads me to believe that this is a bug in V8's garbage collector.

This is as far as i've been able to get with it on my own. I'm not sure if there is some hack to force V8 to garbage collect these or if we'll just have to wait for them to fix it.

I'm happy to send a pull request with my fix, but I don't really feel confident that its right or that it fully addresses the issue, so I thought it would be better to submit this as an issue first to see what you guys think.

Edit: I should point out that I have seen this happen on a single un-nested ng-repeat, but I wasn't able to create a toy example to reproduce that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions