-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Fix LottieTask leak #2465
Merged
Merged
Fix LottieTask leak #2465
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I investigated leaks with `RememberLottieComposition`` and `LottieAnimationView`, initially thinking that we might need to stop listening to LottieTask when a view or composition gets detached / removed. However, after looking at a heap dump, I realized that the LottieTask was actually finished. It had delivered its result so it didn't have any reason to stay in memory. This moved my suspicion to SynchronousQueue as Android has had issues with queues & worker threads on several occasions (see code for details). Also updated the cached thread pool to create threads named "lottie". Leaks: ``` ┬─── │ GC Root: Thread object │ ├─ java.lang.Thread instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181913 objects │ Thread name: 'pool-88-thread-2' │ ↓ Thread<Java Local> │ ~~~~~~~~~~~~ ├─ java.util.concurrent.SynchronousQueue$TransferStack$SNode instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181909 objects │ ↓ SynchronousQueue$TransferStack$SNode.match │ ~~~~~ ├─ java.util.concurrent.SynchronousQueue$TransferStack$SNode instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181908 objects │ ↓ SynchronousQueue$TransferStack$SNode.item │ ~~~~ ├─ com.airbnb.lottie.LottieTask$LottieFutureTask instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181907 objects │ ↓ LottieTask$LottieFutureTask.this$0 │ ~~~~~~ ├─ com.airbnb.lottie.LottieTask instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181905 objects │ ↓ LottieTask.failureListeners │ ~~~~~~~~~~~~~~~~ ├─ java.util.LinkedHashSet instance │ Leaking: UNKNOWN │ Retaining 113 B in 5 objects │ ↓ LinkedHashSet[element()] │ ~~~~~~~~~~~ ├─ com.airbnb.lottie.compose.RememberLottieCompositionKt$await$2$2 instance │ Leaking: UNKNOWN │ Retaining 12 B in 1 objects │ Anonymous class implementing com.airbnb.lottie.LottieListener │ ↓ RememberLottieCompositionKt$await$2$2.$cont │ ~~~~~ ├─ kotlinx.coroutines.CancellableContinuationImpl instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181892 objects │ ↓ CancellableContinuationImpl.delegate │ ~~~~~~~~ ├─ androidx.compose.ui.test.FrameDeferringContinuationInterceptor$FrameDeferredContinuation instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181888 objects │ ↓ FrameDeferringContinuationInterceptor$FrameDeferredContinuation.continuation │ ~~~~~~~~~~~~ ├─ androidx.compose.ui.test.ApplyingContinuationInterceptor$SendApplyContinuation instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181887 objects │ ↓ ApplyingContinuationInterceptor$SendApplyContinuation.continuation │ ~~~~~~~~~~~~ ├─ com.airbnb.lottie.compose.RememberLottieCompositionKt$lottieComposition$1 instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181886 objects │ Anonymous subclass of kotlin.coroutines.jvm.internal.ContinuationImpl │ ↓ BaseContinuationImpl.completion │ ~~~~~~~~~~ ├─ com.airbnb.lottie.compose.RememberLottieCompositionKt$rememberLottieComposition$3 instance │ Leaking: UNKNOWN │ Retaining 6.2 MB in 181885 objects │ Anonymous subclass of kotlin.coroutines.jvm.internal.SuspendLambda │ $context instance of com.squareup.ui.market.core.theme.MarketContextWrapper, wrapping activity com.squareup.ui.main.MainActivity with mDestroyed = true │ ↓ RememberLottieCompositionKt$rememberLottieComposition$3.$context │ ~~~~~~~~ ╰→ com.squareup.ui.market.core.theme.MarketContextWrapper instance Leaking: YES (MarketContextWrapper wraps an Activity with Activity.mDestroyed true) Retaining 6.2 MB in 181845 objects mBase instance of com.squareup.ui.market.core.theme.MarketContextWrapper, wrapping activity com.squareup.ui.main.MainActivity with mDestroyed = true ``` ``` ┬─── │ GC Root: Thread object │ ├─ java.lang.Thread instance │ Leaking: UNKNOWN │ Retaining 8.1 MB in 257497 objects │ Thread name: 'pool-38-thread-1' │ ↓ Thread<Java Local> │ ~~~~~~~~~~~~ ├─ java.util.concurrent.SynchronousQueue$TransferStack$SNode instance │ Leaking: UNKNOWN │ Retaining 8.1 MB in 257493 objects │ ↓ SynchronousQueue$TransferStack$SNode.match │ ~~~~~ ├─ java.util.concurrent.SynchronousQueue$TransferStack$SNode instance │ Leaking: UNKNOWN │ Retaining 8.1 MB in 257492 objects │ ↓ SynchronousQueue$TransferStack$SNode.item │ ~~~~ ├─ com.airbnb.lottie.LottieTask$LottieFutureTask instance │ Leaking: UNKNOWN │ Retaining 8.1 MB in 257491 objects │ ↓ LottieTask$LottieFutureTask.this$0 │ ~~~~~~ ├─ com.airbnb.lottie.LottieTask instance │ Leaking: UNKNOWN │ Retaining 8.1 MB in 257489 objects │ ↓ LottieTask.failureListeners │ ~~~~~~~~~~~~~~~~ ├─ java.util.LinkedHashSet instance │ Leaking: UNKNOWN │ Retaining 101 B in 4 objects │ ↓ LinkedHashSet[element()] │ ~~~~~~~~~~~ ├─ com.airbnb.lottie.LottieAnimationView$1 instance │ Leaking: UNKNOWN │ Retaining 12 B in 1 objects │ Anonymous class implementing com.airbnb.lottie.LottieListener │ ↓ LottieAnimationView$1.this$0 │ ~~~~~~ ╰→ com.airbnb.lottie.LottieAnimationView instance Leaking: YES (View.mContext references a destroyed activity) Retaining 8.1 MB in 257476 objects View not part of a window view hierarchy View.mAttachInfo is null (view detached) View.mWindowAttachCount = 1 mContext instance of flow.path.FlowPathContextWrapper, wrapping activity com.squareup.ui.main.MainActivity with mDestroyed = true ```
gpeal
approved these changes
Feb 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I investigated leaks with
RememberLottieComposition
andLottieAnimationView
, initially thinking that we might need to stop listening to LottieTask when a view or composition gets detached / removed.However, after looking at a heap dump, I realized that the LottieTask was actually finished. It had delivered its result so it didn't have any reason to stay in memory.
This moved my suspicion to SynchronousQueue as Android has had issues with queues & worker threads on several occasions (see code for details).
Also updated the cached thread pool to create threads named "lottie".
Leaks: