Java 谷歌地图地图视图泄漏
我在Android中的一个片段中添加了一个Google地图视图。到目前为止,这是一张清晰的地图,没有任何标记、选项或其他任何东西。然而,每当我离开这个片段时,应用程序就会出现内存泄漏 我已经尝试了我发现的所有建议的解决方案,比如将MapView附加到片段生命周期,在Java 谷歌地图地图视图泄漏,java,android,google-maps,memory-leaks,leakcanary,Java,Android,Google Maps,Memory Leaks,Leakcanary,我在Android中的一个片段中添加了一个Google地图视图。到目前为止,这是一张清晰的地图,没有任何标记、选项或其他任何东西。然而,每当我离开这个片段时,应用程序就会出现内存泄漏 我已经尝试了我发现的所有建议的解决方案,比如将MapView附加到片段生命周期,在onDestroyView()中将其设置为不为null等等,但是内存泄漏仍然占主导地位 当前代码如下所示: ┬ ├─ com.google.android.gms.internal.location.zzat
onDestroyView()
中将其设置为不为null等等,但是内存泄漏仍然占主导地位
当前代码如下所示:
┬
├─ com.google.android.gms.internal.location.zzat
│ Leaking: NO (it's a GC root)
│ ↓ zzat.zzda
│ ~~~~
├─ com.google.android.gms.common.api.internal.ListenerHolder
│ Leaking: UNKNOWN
│ ↓ ListenerHolder.zajl
│ ~~~~
├─ com.google.android.gms.common.api.internal.ListenerHolder$ListenerKey
│ Leaking: UNKNOWN
│ ↓ ListenerHolder$ListenerKey.zajk
│ ~~~~
├─ package.fragments.MapViewFragment$1
│ Leaking: UNKNOWN
│ Anonymous subclass of com.google.android.gms.location.LocationCallback
│ ↓ MapViewFragment$1.this$0
│ ~~~~~~
╰→ package.fragments.MapViewFragment
Leaking: YES (RefWatcher was watching this and Fragment#mFragmentManager is null and Fragment#mFragmentManager is null)
, retainedHeapSize=null), LeakingInstance(referenceKey=3a478407-69a0-4916-8035-42c2bfd2af4e, referenceName=, instanceClassName=android.widget.RelativeLayout, watchDurationMillis=123593, retainedDurationMillis=118589, exclusionStatus=null, leakTrace=
┬
├─ com.google.maps.api.android.lib6.gmm6.vector.q
│ Leaking: NO (it's a GC root)
│ Thread name: 'RenderDrive'
│ ↓ thread q.f
│ ~
├─ com.google.maps.api.android.lib6.gmm6.vector.n
│ Leaking: UNKNOWN
│ ↓ n.k
│ ~
├─ com.google.maps.api.android.lib6.gmm6.api.y
│ Leaking: YES (View detached and has parent)
│ View#mParent is set
│ View#mAttachInfo is null (view detached)
│ View.mWindowAttachCount=1
│ ↓ y.mParent
├─ android.widget.FrameLayout
│ Leaking: YES (y↑ is leaking and View detached and has parent)
│ View#mParent is set
│ View#mAttachInfo is null (view detached)
│ View.mWindowAttachCount=1
│ ↓ FrameLayout.mParent
├─ com.google.android.gms.maps.MapView
│ Leaking: YES (FrameLayout↑ is leaking and View detached and has parent)
│ View#mParent is set
│ View#mAttachInfo is null (view detached)
│ View.mWindowAttachCount=1
│ ↓ MapView.mParent
╰→ android.widget.RelativeLayout
Leaking: YES (RefWatcher was watching this)
View#mParent is null
View#mAttachInfo is null (view detached)
View.mWindowAttachCount=1, retainedHeapSize=null)])
片段映射.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
泄漏跟踪如下所示:
┬
├─ com.google.android.gms.internal.location.zzat
│ Leaking: NO (it's a GC root)
│ ↓ zzat.zzda
│ ~~~~
├─ com.google.android.gms.common.api.internal.ListenerHolder
│ Leaking: UNKNOWN
│ ↓ ListenerHolder.zajl
│ ~~~~
├─ com.google.android.gms.common.api.internal.ListenerHolder$ListenerKey
│ Leaking: UNKNOWN
│ ↓ ListenerHolder$ListenerKey.zajk
│ ~~~~
├─ package.fragments.MapViewFragment$1
│ Leaking: UNKNOWN
│ Anonymous subclass of com.google.android.gms.location.LocationCallback
│ ↓ MapViewFragment$1.this$0
│ ~~~~~~
╰→ package.fragments.MapViewFragment
Leaking: YES (RefWatcher was watching this and Fragment#mFragmentManager is null and Fragment#mFragmentManager is null)
, retainedHeapSize=null), LeakingInstance(referenceKey=3a478407-69a0-4916-8035-42c2bfd2af4e, referenceName=, instanceClassName=android.widget.RelativeLayout, watchDurationMillis=123593, retainedDurationMillis=118589, exclusionStatus=null, leakTrace=
┬
├─ com.google.maps.api.android.lib6.gmm6.vector.q
│ Leaking: NO (it's a GC root)
│ Thread name: 'RenderDrive'
│ ↓ thread q.f
│ ~
├─ com.google.maps.api.android.lib6.gmm6.vector.n
│ Leaking: UNKNOWN
│ ↓ n.k
│ ~
├─ com.google.maps.api.android.lib6.gmm6.api.y
│ Leaking: YES (View detached and has parent)
│ View#mParent is set
│ View#mAttachInfo is null (view detached)
│ View.mWindowAttachCount=1
│ ↓ y.mParent
├─ android.widget.FrameLayout
│ Leaking: YES (y↑ is leaking and View detached and has parent)
│ View#mParent is set
│ View#mAttachInfo is null (view detached)
│ View.mWindowAttachCount=1
│ ↓ FrameLayout.mParent
├─ com.google.android.gms.maps.MapView
│ Leaking: YES (FrameLayout↑ is leaking and View detached and has parent)
│ View#mParent is set
│ View#mAttachInfo is null (view detached)
│ View.mWindowAttachCount=1
│ ↓ MapView.mParent
╰→ android.widget.RelativeLayout
Leaking: YES (RefWatcher was watching this)
View#mParent is null
View#mAttachInfo is null (view detached)
View.mWindowAttachCount=1, retainedHeapSize=null)])
然而,我已经尝试将生命周期方法从onDestroy
移动到onDestroyView
等等
每次我离开MapFragment时,内存泄漏大约为1到2MB。
我希望可以修复此漏洞,但我不知道再尝试什么。第一步是确认断点调用destroy(destroyView)或记录方法-destroy不保证被调用。一些信息:。我已经检查了此项,并且重复调用了
ondestory(View)
方法。调用ondestory(View)
方法时,内存泄漏仍然存在。是否有任何解决方案来修复此内存泄漏?是否有任何解决方案@MaximilianSpeicher?@ysfcyln不,我当时没有解决方案,但我最近没试过。