Repository navigation
Description
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
fhackenberger commentedon Nov 22, 2017
woppa684 commentedon Nov 23, 2017
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.
alexhobbs commentedon Aug 15, 2018
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.
DougJordan9 commentedon Nov 10, 2018
Is there a solution to this problem? I think this is a major issue that essentially renders the animation library useless...
DieterGehring commentedon Dec 9, 2019
I face the same issue with code below.
Is there any solution?
ARadauer commentedon Oct 21, 2020
There is a very nice example for animations at the bottom of https://angular.io/guide/animations -> http://animationsftw.in/
This are the DOM Nodes after a while:

Don't know if its the same issue but it looks dodgy
JeanMeche commentedon Jul 4, 2023
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
TransitionAnimationEngineisn't freed in some situations. I've proposed a fix in #50929The
TimelineAnimationEngineis another one, lets track only this one here !BraianS commentedon Mar 17, 2024
Goodnight.
This issue can be closed because #24197 and #50533 are the same and are also close.
Thanks.
angular-automatic-lock-bot commentedon Apr 17, 2024
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.