Skip to content

Detached elements stay in memory when animated #50533

@waterplea

Description

@waterplea

Which @angular/* package(s) are the source of the bug?

animations

Is this a regression?

No

Description

If you use an animation on the element and toggle it with ngIf, it seems to be staying in the memory according to Detached Elements debugger in Edge. On a brief look it appears that maybe a WeakMap has to be used some place instead of Map:

image

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-vnp1kv

  1. Open this link in Edge browser
  2. Open DevTools -> Detached Elements tab
  3. Select the correct frame in the dropdown on that tab (it should say https://stackblitz-starters-vnp1kv.stackblitz.io/)
  4. Toggle element a few times with the button
  5. Press get detached element
  6. Press analyze to see what keeps the elements there (you will see the above screenshot)

Please provide the exception or error you saw

Multiple copies of DOM element stay in memory.

Please provide the environment you discovered this bug in (run ng version)

I noticed it in Angular 12, but it is reproducible in 16 as well, see linked StackBlitz

Anything else?

An article I learned about Detached Elements from:
https://blogs.windows.com/msedgedev/2021/12/09/debug-memory-leaks-detached-elements-tool-devtools/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions