【问题标题】:Why does Leak Canary detect Google firebase APIs as Leaks?为什么 Leak Canary 会将 Google Firebase API 检测为泄漏?
【发布时间】:2023-03-20 19:05:01
【问题描述】:

为什么 Leak Canary 会将 Google Firebase API 检测为泄漏? 当我在使用 firebase 时启动应用程序时,它会不断检测内存泄漏。有没有办法阻止这种情况?谢谢。

┬───
│ GC Root: Global variable in native code
│
├─ com.google.firebase.auth.api.fallback.service.zza instance
│    Leaking: UNKNOWN
│    Retaining 634 B in 9 objects
│    zza instance of com.google.firebase.auth.api.fallback.service.
│    FirebaseAuthFallbackService
│    ↓ zza.zza
│          ~~~
╰→ com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService
​  instance
​     Leaking: YES (ObjectWatcher was watching this because com.google.firebase.
​     auth.api.fallback.service.FirebaseAuthFallbackService received
​     Service#onDestroy() callback)
​     Retaining 606 B in 8 objects
​     key = 7ab80331-3185-47d4-b999-118434212080
​     watchDurationMillis = 5284
​     retainedDurationMillis = 278
​     mApplication instance of com.example.app.App
​     mBase instance of android.app.ContextImpl

METADATA

Build.VERSION.SDK_INT: 27
Build.MANUFACTURER: iLA
LeakCanary version: 2.6
App process name: com.example.app
Stats: LruCache[maxSize=3000,hits=1327,misses=42351,hitRate=3%]
RandomAccess[bytes=2171000,reads=42351,travel=15377633875,range=14122402,size=17
486349]
Heap dump reason: 1 retained objects, app is not visible
Analysis duration: 16095 ms```

【问题讨论】:

标签: firebase leakcanary


【解决方案1】:

https://github.com/firebase/firebase-android-sdk/issues/2387 编辑:
以下是忽略该站点小泄漏的建议解决方法:
First, disable the automatic install:

<resources>
  <bool name="leak_canary_watcher_auto_install">false</bool>
</resources>
Then install LeakCanary manually in your debug application, ignoring FirebaseAuthFallbackService:

class DebugExampleApplication : ExampleApplication() {

  override fun onCreate() {
    super.onCreate()

    val delegate = ReachabilityWatcher { watchedObject, description ->
      if (watchedObject::class.java.name != "com.google.firebase.auth.api.fallback.service.FirebaseAuthFallbackService
​  instance") {
        AppWatcher.objectWatcher.expectWeaklyReachable(watchedObject, description)
      }
    }

    val watchersToInstall = AppWatcher.appDefaultWatchers(application, delegate)

    AppWatcher.manualInstall(
      application = application,
      watchersToInstall = watchersToInstall
    )
  }
}

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
  • 谢谢@SoniaSamipillai,我已经编辑了答案
猜你喜欢
  • 2019-03-13
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多