LuckSiege / LuckSiege/PictureSelector

预览视频播放未完成时返回会导致内存泄漏

Open
#2,424 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
13.6k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

Current use version?

当前使用的版本是多少?
3.10.3

Will this problem occur in demo?

Demo能否复现这问题?
100%复现,预览视频点播放,然后返回,LeakCanary就会提示内存泄漏

Describe the problem or provide an error log?

描述问题或提供错误log?
//调用方式
PictureSelector.create(context) //context为fragment getContext()

//LeakCanary 日志
D/LeakCanary: ====================================
D/LeakCanary: HEAP ANALYSIS RESULT
D/LeakCanary: ====================================
D/LeakCanary: 0 APPLICATION LEAKS
D/LeakCanary: 
D/LeakCanary: References underlined with "~~~" are likely causes.
D/LeakCanary: Learn more at https://squ.re/leaks.
D/LeakCanary: ====================================
D/LeakCanary: 0 LIBRARY LEAKS
D/LeakCanary: 
D/LeakCanary: A Library Leak is a leak caused by a known bug in 3rd party code that you do not have control over.
D/LeakCanary: See https://square.github.io/leakcanary/fundamentals-how-leakcanary-works/#4-categorizing-leaks
D/LeakCanary: ====================================
D/LeakCanary: 11 UNREACHABLE OBJECTS
D/LeakCanary: 
D/LeakCanary: An unreachable object is still in memory but LeakCanary could not find a strong reference path
D/LeakCanary: from GC roots.
D/LeakCanary: 
D/LeakCanary: com.luck.picture.lib.PictureSelectorFragment instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because com.luck.picture.lib.PictureSelectorFragment received
D/LeakCanary: ​  Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
D/LeakCanary: ​  key = a315648e-ee6c-448f-904c-10812a29c861
D/LeakCanary: ​  watchDurationMillis = 7094
D/LeakCanary: ​  retainedDurationMillis = 2094
D/LeakCanary: 
D/LeakCanary: androidx.lifecycle.SavedStateHandlesVM instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because androidx.lifecycle.SavedStateHandlesVM received
D/LeakCanary: ​  ViewModel#onCleared() callback)
D/LeakCanary: ​  key = e723473e-af90-4e1e-ae1b-941d43446299
D/LeakCanary: ​  watchDurationMillis = 7095
D/LeakCanary: ​  retainedDurationMillis = 2095
D/LeakCanary: 
D/LeakCanary: androidx.constraintlayout.widget.ConstraintLayout instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because com.luck.picture.lib.PictureSelectorFragment received
D/LeakCanary: ​  Fragment#onDestroyView() callback (references to its views should be cleared to prevent leaks) and View.mContext
D/LeakCanary: ​  references a destroyed activity)
D/LeakCanary: ​  key = 232e65d1-559e-48d0-a063-fd59afa0f6d7
D/LeakCanary: ​  watchDurationMillis = 7095
D/LeakCanary: ​  retainedDurationMillis = 2095
D/LeakCanary: ​  View not part of a window view hierarchy
D/LeakCanary: ​  View.mAttachInfo is null (view detached)
D/LeakCanary: ​  View.mWindowAttachCount = 1
D/LeakCanary: ​  mContext instance of com.luck.picture.lib.basic.PictureSelectorSupporterActivity with mDestroyed = true
D/LeakCanary: 
D/LeakCanary: com.bumptech.glide.manager.SupportRequestManagerFragment instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because com.bumptech.glide.manager.SupportRequestManagerFragment
D/LeakCanary: ​  received Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
D/LeakCanary: ​  key = 5b5b007d-a06e-4e5f-85dc-a98cdc57be38
D/LeakCanary: ​  watchDurationMillis = 7097
D/LeakCanary: ​  retainedDurationMillis = 2097
D/LeakCanary: 
D/LeakCanary: com.luck.picture.lib.basic.PictureSelectorSupporterActivity instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because com.luck.picture.lib.basic.PictureSelectorSupporterActivity
D/LeakCanary: ​  received Activity#onDestroy() callback and Activity#mDestroyed is true)
D/LeakCanary: ​  key = e8ac9286-b14e-4011-b0fc-accb54fff13b
D/LeakCanary: ​  watchDurationMillis = 7101
D/LeakCanary: ​  retainedDurationMillis = 2101
D/LeakCanary: ​  mApplication instance of com.xl.App
D/LeakCanary: ​  mBase instance of androidx.appcompat.view.ContextThemeWrapper
D/LeakCanary: 
D/LeakCanary: androidx.lifecycle.ReportFragment instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because androidx.lifecycle.ReportFragment received
D/LeakCanary: ​  Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
D/LeakCanary: ​  key = 3eaf6ce8-dce3-44b6-a734-f71eb70c2ece
D/LeakCanary: ​  watchDurationMillis = 7101
D/LeakCanary: ​  retainedDurationMillis = 2101
D/LeakCanary: 
D/LeakCanary: androidx.lifecycle.SavedStateHandlesVM instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because androidx.lifecycle.SavedStateHandlesVM received
D/LeakCanary: ​  ViewModel#onCleared() callback)
D/LeakCanary: ​  key = 6596db22-72db-4043-b273-c257b7624f0b
D/LeakCanary: ​  watchDurationMillis = 7102
D/LeakCanary: ​  retainedDurationMillis = 2101
D/LeakCanary: 
D/LeakCanary: androidx.fragment.app.FragmentManagerViewModel instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because androidx.fragment.app.FragmentManagerViewModel received
D/LeakCanary: ​  ViewModel#onCleared() callback)
D/LeakCanary: ​  key = d45420bb-2c4d-4c4a-9989-6d86574b2235
D/LeakCanary: ​  watchDurationMillis = 7102
D/LeakCanary: ​  retainedDurationMillis = 2102
D/LeakCanary: 
D/LeakCanary: com.luck.picture.lib.PictureSelectorPreviewFragment instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because com.luck.picture.lib.PictureSelectorPreviewFragment received
D/LeakCanary: ​  Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
D/LeakCanary: ​  key = 4c08be25-6b28-4a6d-8dc0-51f5da5fcd3e
D/LeakCanary: ​  watchDurationMillis = 7924
D/LeakCanary: ​  retainedDurationMillis = 2923
D/LeakCanary: 
D/LeakCanary: androidx.lifecycle.SavedStateHandlesVM instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because androidx.lifecycle.SavedStateHandlesVM received
D/LeakCanary: ​  ViewModel#onCleared() callback)
D/LeakCanary: ​  key = 9965f548-dd40-4b6f-8ac4-3c57eb2de514
D/LeakCanary: ​  watchDurationMillis = 7953
D/LeakCanary: ​  retainedDurationMillis = 2952
D/LeakCanary: 
D/LeakCanary: androidx.constraintlayout.widget.ConstraintLayout instance
D/LeakCanary: ​  Leaking: YES (ObjectWatcher was watching this because com.luck.picture.lib.PictureSelectorPreviewFragment received
D/LeakCanary: ​  Fragment#onDestroyView() callback (references to its views should be cleared to prevent leaks) and View.mContext
D/LeakCanary: ​  references a destroyed activity)
D/LeakCanary: ​  key = 6eca18f9-9470-455b-999e-84c62e59efd9
D/LeakCanary: ​  watchDurationMillis = 7954
D/LeakCanary: ​  retainedDurationMillis = 2953
D/LeakCanary: ​  View not part of a window view hierarchy
D/LeakCanary: ​  View.mAttachInfo is null (view detached)
D/LeakCanary: ​  View.mWindowAttachCount = 1
D/LeakCanary: ​  mContext instance of com.luck.picture.lib.basic.PictureSelectorSupporterActivity with mDestroyed = true
D/LeakCanary: ====================================
D/LeakCanary: METADATA
D/LeakCanary: 
D/LeakCanary: Please include this in bug reports and Stack Overflow questions.
D/LeakCanary: 
D/LeakCanary: Build.VERSION.SDK_INT: 31
D/LeakCanary: Build.MANUFACTURER: Google
D/LeakCanary: LeakCanary version: 2.9.1
D/LeakCanary: Class count: 26050
D/LeakCanary: Instance count: 242495
D/LeakCanary: Primitive array count: 149809
D/LeakCanary: Object array count: 34812
D/LeakCanary: Thread count: 48
D/LeakCanary: Heap total bytes: 29415294
D/LeakCanary: Bitmap count: 36
D/LeakCanary: Bitmap total bytes: 39112560
D/LeakCanary: Large bitmap count: 0
D/LeakCanary: Large bitmap total bytes: 0
D/LeakCanary: Stats: LruCache[maxSize=3000,hits=120928,misses=218960,hitRate=35%]
D/LeakCanary: RandomAccess[bytes=10984618,reads=218960,travel=72557778771,range=35927588,size=43759638]
D/LeakCanary: Heap dump reason: 11 retained objects, app is visible
D/LeakCanary: Analysis duration: 33376 ms
D/LeakCanary: Heap dump timestamp: 1657763946964
D/LeakCanary: Heap dump duration: 3422 ms
D/LeakCanary: ====================================

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with version 3.10.3 by starting video preview and returning before playback finishes, then inspect the LeakCanary output. Trace the lifecycle of PictureSelectorFragment, PictureSelectorPreviewFragment, and PictureSelectorSupporterActivity during this flow. Done means returning from an unfinished preview no longer leaves these objects reported as leaking.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.