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.

ngRepeat "track by" possible memory leak #16776

Closed
@bensgroi

Description

@bensgroi

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:

Adding a track by to an ngRepeat causes a memory leak, so that the component's controller is retained in memory.

Expected / new behavior:

Using track by on an ngRepeat should not cause any side effects.

Minimal reproduction of the problem with instructions:

Plunker
To see the memory leak in action, you'll need to run the demo in its own tab: https://run.plnkr.co/plunks/pToAURpUzO2pdOq6H0Yf/

It contains two child components, a "leaky" version and a "non-leaky" version, the only difference between them being the addition of a "track by" on the leaky one.

  1. Click on "Leaky Component", then "Non-Leaky Component", then "Reset"
  2. Take a heap snapshot. Filter on "leaky". You'll see that the "leaky" component is still in memory, though not reachable. The "non-leaky" component has been GC'ed and is no longer on the heap.
    image

The presence of "track by" seems to cause a leak. Using track by $index has the same effect. This seems like a really obvious bug, but I haven't been able to find anything related to it here yet. Am I missing something?

AngularJS version: 1.7.5

Also reproduced in 1.5.8

Browser: Chrome 70

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions