Skip to content

TimelineAnimationEngine leaks memory (entries in _animations) #20585

Closed

Description

@fhackenberger

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] 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

Current behavior

When creating animations like this:

const myAnimation = this.animBuilder.build([
	style({ opacity: 1 }),
	animate('300 ms ease', style({ opacity: 0 }))
]);
const player = myAnimation.create(container.nativeElement);
player.onDone(() => { ...; player.destroy(); });
player.play();

This individual AnimationMetadata (i.e. the steps it needs to go through) is registered with TimelineAnimationEngine stored in TimelineAnimationEngine._animations. However there is no code in that class that will ever clear entries from the map _animations. IDs for new animations are created within BrowserAnimationBuilder, by simply incrementing from the previous issues ID.

The callflow is like this:

BrowserAnimationBuilder.build() -> issueAnimationCommand() -> AnimationRenderer.setProperty(name: "@@xxxx:register") -> AnimationEngine.process() -> TimelineAnimationEngine.command() -> TimelineAnimationEngine.register()

Expected behavior

The animation that is returned from build() needs to provide a destroy() method that it de-registers the animation itself.

Minimal reproduction of the problem with instructions

See this plnkr, open the preview in a separate (private) window in Chrome and let it run for a few animation cycles. Then take three memory heap snapshots with about 10 seconds in between. Select the third and select 'Objects allocated between Snapshot 1 and 2'. Observe that there is one retained Object entry for each animation that was created using build().

What is the motivation / use case for changing the behavior?

I stumbled upon this error, because from the API of AnimationBuilder, it was completely unclear that the animation would be centrally registered and cause memory to remain there during the whole life of the application.

The use case for creating lots of animations, is that for example the duration may vary according to user input, so there must be a way to dispose of animations entirely for that use-case to be viable.

Environment


Angular version: 5.0.2


Browser:
- [x] Chrome (desktop) version 62
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version 57
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v6.10.1  
- Platform: Linux (Ubuntu 16.04.3) 

Others:

Activity

  1. fhackenberger commented on Nov 22, 2017

    @fhackenberger
    Author

    screenshot from 2017-11-22 14-40-18

  2. woppa684 commented on Nov 23, 2017

    @woppa684

    I have the same issue with the TransitionAnimationEngine (in combination with routing). When I come back to the route that has animations they are added again and again to this statesByElement map and that leaves a huge number of elements in the detached DOM.

    leak

  3. added
    area: animations
    memory leak
    on Nov 27, 2017
  4. added this to the needsTriage milestone on Feb 26, 2018
  5. modified the milestones: needsTriage, Backlog on May 15, 2018
  6. alexhobbs commented on Aug 15, 2018

    @alexhobbs

    Do you need anything to help reproduce this? We see this in a simple animating “cards” application where after one day of transitioning between cards every ten seconds the app crashes due to memory usage. Debugging this shows it to be the growing number of detached nodes. The workaround is to use native CSS where possible.

    Possibly also related to #24197 and #18606 which include performance stats.

  7. DougJordan9 commented on Nov 10, 2018

    @DougJordan9

    Is there a solution to this problem? I think this is a major issue that essentially renders the animation library useless...

  8. DieterGehring commented on Dec 9, 2019

    @DieterGehring

    I face the same issue with code below.
    Is there any solution?

                // first build the animation
                let myAnimation = this._builder.build([
                    style({ bottom: curPos }),
                    animate("750ms ease-in", style({ bottom: this._lastPosition }))
                ]);
    
                // then create a player from it
                if (this.NeedleElement != null && this.NeedleElement.nativeElement) {
                    let player = myAnimation.create(this.NeedleElement.nativeElement as HTMLElement);
                    player.play();
                }
    
    
  9. added
    P3
    on Oct 1, 2020
  10. ARadauer commented on Oct 21, 2020

    @ARadauer
  11. JeanMeche commented on Jul 4, 2023

    @JeanMeche
    Member

    I've been investigating the memory leaks of the animation module.

    The issue reported by @woppa684 is the same as #24197 & #50533 : The cache of the TransitionAnimationEngine isn't freed in some situations. I've proposed a fix in #50929

    The TimelineAnimationEngine is another one, lets track only this one here !

  12. BraianS commented on Mar 17, 2024

    @BraianS

    Goodnight.
    This issue can be closed because #24197 and #50533 are the same and are also close.

    Thanks.

  13. angular-automatic-lock-bot commented on Apr 17, 2024

    @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.

  14. locked and limited conversation to collaborators on Apr 17, 2024
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: mediumhotlist: devrelmemory leaktype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions