Blankj / Blankj/AndroidUtilCode

PermissionUtils 内存泄漏

Abierto
#1,708 1 comentario 0 reacciones 1 asignado Reclamado por @Blankj Ver en GitHub
bug
Lenguaje dominante
Java
Estrellas
33.6k
Forks
10.6k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## 描述 Bug

使用工具类时发生内存泄漏

- AndroidUtilCode 的版本:utilcodex:1.31.1
- 出现 Bug 的设备型号:Pixel5
- 设备的 Android 版本:API 31

## 相关代码

```
/**
* 快速请求权限
*/
fun request(
onAllGranted: () -> Unit,
@PermissionConstants.PermissionGroup vararg permissions: String,
onDenied: () -> Unit = { ToastUtils.showLong("未开启相关权限") },
) {
PermissionUtils.permission(*permissions)
.rationale { _, shouldRequest -> showRationaleDialog(mContext, shouldRequest, mLifecycle) }
.callback(object : PermissionUtils.SingleCallback {
override fun callback(
isAllGranted: Boolean,
granted: MutableList,
deniedForever: MutableList,
denied: MutableList
) {
if (isAllGranted) {
// 全部通过
onAllGranted()
return
}
if (deniedForever.isNotEmpty()) {
// 有永久拒绝的权限
showOpenAppSettingDialog(mContext, mLifecycle)
return
}
// 没有全部通过
onDenied()
}
})
.request()
}
```

## 异常堆栈

```
====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS

References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.

199775 bytes retained by leaking objects
Displaying only 1 leak trace out of 5 with the same signature
Signature: b7c81aff62fcf437fefb4ace2f786ab2fa9ed657
┬───
│ GC Root: Global variable in native code

├─ android.app.AppOpsManager$3 instance
│ Leaking: UNKNOWN
│ Retaining 536 B in 1 objects
│ Anonymous subclass of com.android.internal.app.IAppOpsActiveCallback$Stub
│ ↓ AppOpsManager$3.val$callback
│ ~~~~~~~~~~~~
├─ android.permission.PermissionUsageHelper instance
│ Leaking: UNKNOWN
│ Retaining 126 B in 5 objects
│ mContext instance of com.blankj.utilcode.util.UtilsTransActivity with mDestroyed = true
│ ↓ PermissionUsageHelper.mContext
│ ~~~~~~~~
╰→ com.blankj.utilcode.util.UtilsTransActivity instance
​ Leaking: YES (ObjectWatcher was watching this because com.blankj.utilcode.util.UtilsTransActivity received
​ Activity#onDestroy() callback and Activity#mDestroyed is true)
​ Retaining 40.0 kB in 833 objects
​ key = 5ee3e8ef-f9dd-418d-83ea-cadb4a2a98ac
​ watchDurationMillis = 5924
​ retainedDurationMillis = 923
​ mApplication instance of com.xxx.bedrock.app.AppApplication
​ mBase instance of androidx.appcompat.view.ContextThemeWrapper
====================================
0 LIBRARY LEAKS

A Library Leak is a leak caused by a known bug in 3rd party code that you do not have control over.
See https://square.github.io/leakcanary/fundamentals-how-leakcanary-works/#4-categorizing-leaks
====================================
0 UNREACHABLE OBJECTS

An unreachable object is still in memory but LeakCanary could not find a strong reference path
from GC roots.
====================================
METADATA

Please include this in bug reports and Stack Overflow questions.

Build.VERSION.SDK_INT: 31
Build.MANUFACTURER: unknown
LeakCanary version: 2.9.1
App process name: com.xxx.basegis
Class count: 28040
Instance count: 242816
Primitive array count: 157968
Object array count: 30981
Thread count: 46
Heap total bytes: 36150526
Bitmap count: 23
Bitmap total bytes: 1030595
Large bitmap count: 0
Large bitmap total bytes: 0
Stats: LruCache[maxSize=3000,hits=120915,misses=210835,hitRate=36%]
RandomAccess[bytes=10498560,reads=210835,travel=107894972371,range=38766153,size=50721662]
Heap dump reason: 8 retained objects, app is visible
Analysis duration: 5911 ms
Heap dump file path: /storage/emulated/0/Download/leakcanary-com.xxx.basegis/2022-10-24_08-03-18_533.hprof
Heap dump timestamp: 1666598612228
Heap dump duration: 1591 ms
====================================
```

## 截图

无。

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.