-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memory leak while unmounting the lottie component #1010
Comments
This is a very accurate representation of things. We have been using animationref.current. Reset() on unmount but this has to be automatic process. |
Well, I went ahead and wrote this in the componentWillUnmount(): void {
if (this.props.autoPlay) this.reset();
} Although the |
ahh i m not sure of the behavior with class components. we use it like this
in conjugation with react-navigation. This is how it looks like.
…On Mon, Apr 17, 2023 at 12:36 PM Prateek Thapa ***@***.***> wrote:
This is a very accurate representation of things. We have been using
animationref.current. Reset() on unmount but this has to be an automatic
process.
Well, I went ahead and wrote this in the LottieView library component
itself
componentWillUnmount(): void {
if (this.props.autoPlay) this.reset();
}
Although the reset command is being triggered, the problem still persists.
—
Reply to this email directly, view it on GitHub
<#1010 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGGUBYF6IWX3NDMP4EMQTLXBTTY7ANCNFSM6AAAAAAXAGMLOU>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
useFocusEffect(
useCallback(() => {
if (animation.current) {
animation.current.play();
}
return () => {
animation.current && animation.current.reset();
};
}, []),
);
…On Mon, Apr 17, 2023 at 1:40 PM Nikit Phadke ***@***.***> wrote:
ahh i m not sure of the behavior with class components. we use it like
this in conjugation with react-navigation. This is how it looks like.
On Mon, Apr 17, 2023 at 12:36 PM Prateek Thapa ***@***.***>
wrote:
> This is a very accurate representation of things. We have been using
> animationref.current. Reset() on unmount but this has to be an automatic
> process.
>
> Well, I went ahead and wrote this in the LottieView library component
> itself
>
> componentWillUnmount(): void {
> if (this.props.autoPlay) this.reset();
> }
>
> Although the reset command is being triggered, the problem still
> persists.
>
> —
> Reply to this email directly, view it on GitHub
> <#1010 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABGGUBYF6IWX3NDMP4EMQTLXBTTY7ANCNFSM6AAAAAAXAGMLOU>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***
> com>
>
|
Thank you for the detailed explanation. I will try to look into that on the weekend. However, the Do you have new architecture turned on? Meanwhile, can you try adding |
Thanks for your quick reply. In our organizational code, the new architecture is not turned on. I could see no changes by adding |
@matinzd Perhaps. I dont know how or why the above solution works. Just that we get back the RAM engaged by lottie animation this way which we otherwise dont. would love for a more elegant solution if one is possible. 🤘 |
This is indeed a problem. take a look at the following code and include this component on a screen which refreshes from time to time.
Lets say the component is used like this
});` Now every time the query fetches, the screen will keep asking for more and more RAM eventually bombing out the App. :( |
Any solution for this? |
It appears that Android is not experiencing this issue, as all views are being correctly managed and RAM is released as soon as the view is unmounted. However, I'll investigate further to determine what might be going on behind the scenes with iOS. lottie_android_perf.mp4 |
Any news @matinzd ? |
I put some time into that but still no luck. I will try again on the weekend. |
@matinzd have u tried? 😄 |
@matinzd would really appreciate an update on this. The library is working near perfect for us except for this problem. |
Now, we have addressed the issue and the pull request is in review. Waiting for @emilioicai with higher access to approve. |
The fix is included in v6.0.0-rc.8: https://github.com/lottie-react-native/lottie-react-native/releases/tag/v6.0.0-rc.8 |
* fix: memory leak on iOS on deallocation Fixes: lottie-react-native/lottie-react-native#1010 * fix: add weak reference in setSourceURL * fix: memory leak issue (#1056) --------- Co-authored-by: Parsa Nasirimehr <40071952+TheRogue76@users.noreply.github.com>
* fix: memory leak on iOS on deallocation Fixes: lottie-react-native/lottie-react-native#1010 * fix: add weak reference in setSourceURL * fix: memory leak issue (#1056) --------- Co-authored-by: Parsa Nasirimehr <40071952+TheRogue76@users.noreply.github.com>
Description
The Lottie React Native component seems to be causing a memory leak when unmounted. After the component is unmounted, the device does not release the memory, which causes the RAM usage to spike up.
Haven't checked in Android devices yet.
Steps to Reproduce
Repo: https://github.com/pSapien/lottie-memory-leak
Screen.Recording.2023-04-16.at.21.30.50.mov
Expected behavior:
Actual behavior:
When the Lottie React Native component is unmounted, the device does not release the memory used by the component, causing the memory leak.
Versions
lottie-react-native: 6.0.0-rc.3, 6.0.0-rc.2, 5.1.5
The text was updated successfully, but these errors were encountered: