Skip to content

Memory leak with animations in combination with @HostBinding #24197

Closed

Description

@MrHus

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

When using animations in combination with a @HostBinding dom nodes are not released.

Open https://angular-5-example-tm3ghr.stackblitz.io/bar in chrome and open the performance
monitor. Toggle on "DOM nodes". Note the starting number, now switch between foo and bar a number of times. Now click "Collect garbage" observe that the "DOM nodes" will keep growing.

Expected behavior

That the DOM nodes are garbage collected, and that the DOM nodes do not increase indefinitly.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/angular-5-example-tm3ghr?file=app%2Fcontent-state.component.ts

Environment


Angular version: 5.2.10


Browser:
- [x ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Activity

  1. MrHus commented on May 30, 2018

    @MrHus
    Author

    Possibly related: #18606

  2. added
    area: animations
    on May 30, 2018
  3. added this to the needsTriage milestone on May 30, 2018
  4. splincode commented on May 31, 2018

    @splincode
    Contributor

    @MrHus

    Can you add a performance monitor screen? I would like to see gif in order to understand what is wrong and how it affects the application..

  5. splincode commented on May 31, 2018

    @splincode
    Contributor

    @MrHus Thank you, it's perfect example

  6. g-stone7 commented on Jun 26, 2018

    @g-stone7

    We discovered similar problems with Angular 4,5 and 6 as well. Any ideas where the leak comes from? When will it be fixed?

  7. added
    memory leak
    on Jul 17, 2018
  8. modified the milestones: needsTriage, Backlog on Jul 17, 2018
  9. jsim5446 commented on Jun 7, 2020

    @jsim5446

    Here is a repro that demonstrates this bug is still not fixed (or maybe regressed at some point) in Angular 9.1.9:

    https://stackblitz.com/edit/angular-ivy-wfjsyc

    This example also shows a work-around that will eliminate the leak by adding a no-op animation in the parent component.

    Note that this issue is also the root cause of a memory leak in Angular Material sidenav component (technically the MatDrawer component) as described in angular/components#8862

  10. added
    P3
    on Oct 1, 2020
  11. jlgabbar commented on Feb 3, 2021

    @jlgabbar

    Any update on this?

  12. andresbm05 commented on Oct 5, 2022

    @andresbm05

    Any update on this? I updated the repro @jsim5446 did to Angular 14.2 and the issue still happens https://stackblitz.com/edit/angular-v14-playground-62uxm9

  13. JeanMeche commented on Jul 3, 2023

    @JeanMeche
    Member

    @andresbm05 I can confirm this reproduces the leak.

    Also we have another issue already open on this.

    I'll close this one and lets continue tracking in #20585

    My bad the issue is a bit different.

    A minimal repro :

    @Component({
      selector: '[element]',
      template: 'This element is animated',
      standalone: true,
      animations: [
        trigger(`fade`, [
          transition(`:leave`, [style({ opacity: 1 }), animate(`300ms ease-in-out`, style({ opacity: 0 }))]),
        ]),
      ],
      host: { '[@fade]': '' },
    })
    export class ElementComponent {}
    
    @Component({
      selector: 'app-root',
      standalone: true,
      imports: [NgIf, ElementComponent],
      template: `
        <button (click)="v = !v">Toggle</button>
        <div *ngIf="v" element></div>
      `,
    })
    export class AppComponent {
      v = true;
    }
    
    bootstrapApplication(AppComponent, { providers: [provideAnimations()] });
    

    Note: the leak only appears when there is a :leave animation. If there is only a :enter there is no leak.

  14. added a commit that references this issue on Jul 8, 2023
    f0e1011
  15. added a commit that references this issue on Jul 11, 2023
    f920fcb
  16. added a commit that references this issue on Jul 26, 2023
    f61499b
  17. angular-automatic-lock-bot commented on Aug 11, 2023

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  18. locked and limited conversation to collaborators on Aug 11, 2023
  19. added a commit that references this issue on Jan 23, 2024
    2b11f9c
  20. added a commit that references this issue on Jun 6, 2024
    a14bdfe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: animationsfreq2: mediummemory leakstate: has PRtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions