Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ```
- Loading branch information