You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A memory leak has been identified in the Animated API for react-native-web, specifically in the AnimatedWithChildren class and related animations. The issue arises when rendering multiple animated components using transforms and interpolation. Over time, internal arrays (like children in AnimatedWithChildren) grow indefinitely, leading to increased memory usage and performance degradation.
Expected behavior
Memory usage should remain stable over time as animations run and re-renders occur, regardless of the number of Animated components rendered.
Animated values (Animated.Value, Animated.ValueXY, etc.) should not accumulate indefinitely in the internal array of AnimatedWithChildren.
The AnimatedWithChildren class or related classes should ensure that duplicate or unused children are not repeatedly added to its array.
Animations should not degrade in performance as time progresses, even with multiple animated components and transformations (e.g., transform styles with interpolated values).
Steps to reproduce
Implement a component or file that periodically renders multiple Animated elements using transform and interpolate, as these trigger the issue more frequently.
Monitor performance degradation visually as animations run.
Use tools like Chrome DevTools to confirm memory growth over time, by taking heap snapshots.
CodeSandbox isn’t the most reliable environment for demonstrating memory growth due to other objects accumulating during runtime. Instead, I’ve hosted a reproduction of the issue on Netlify here:
You’ll notice performance degradation within approximately 10 seconds, depending on your machine. Using Chrome DevTools or similar tools, you can observe memory snapshots that reveal the growth of Animated elements in the Array constructor.
Example Code
Below is the code used to reproduce the issue. You can implement this yourself to observe the problem:
Animated is maintained in React Native and the code was once copy-pasted into the "vendor" directory here. It hasn't been updated in a while and the goal was to be able to consume it as a package dependency (published by React Native). See facebook/react-native#35263
The issue you're reporting may or may not exist in the current version of Animated in React Native.
Is there an existing issue for this?
Describe the issue
A memory leak has been identified in the Animated API for react-native-web, specifically in the AnimatedWithChildren class and related animations. The issue arises when rendering multiple animated components using transforms and interpolation. Over time, internal arrays (like children in AnimatedWithChildren) grow indefinitely, leading to increased memory usage and performance degradation.
Expected behavior
Memory usage should remain stable over time as animations run and re-renders occur, regardless of the number of Animated components rendered.
Animated values (Animated.Value, Animated.ValueXY, etc.) should not accumulate indefinitely in the internal array of AnimatedWithChildren.
The AnimatedWithChildren class or related classes should ensure that duplicate or unused children are not repeatedly added to its array.
Animations should not degrade in performance as time progresses, even with multiple animated components and transformations (e.g., transform styles with interpolated values).
Steps to reproduce
Package Versions
Test case
https://codesandbox.io/p/sandbox/animated-memory-leak-7j5d2n
Additional comments
CodeSandbox isn’t the most reliable environment for demonstrating memory growth due to other objects accumulating during runtime. Instead, I’ve hosted a reproduction of the issue on Netlify here:
👉 Live Demo
You’ll notice performance degradation within approximately 10 seconds, depending on your machine. Using Chrome DevTools or similar tools, you can observe memory snapshots that reveal the growth of Animated elements in the Array constructor.
Example Code
Below is the code used to reproduce the issue. You can implement this yourself to observe the problem:
Temporary Fix
A potential short-term fix involves modifying the addChild method in AnimatedWithChildren to avoid redundant additions to the children array:
This change eliminates memory growth, but it seems like a hack.
The text was updated successfully, but these errors were encountered: