我已将 Leak Canary 添加到个人 Android 应用程序中,并生成了以下堆栈跟踪:
05-13 06:49:15.589 27088-28230/com.upwardsnorthwards.blueplaqueslondon D/LeakCanary﹕ In com.upwardsnorthwards.blueplaqueslondon:1.2:3.
* com.upwardsnorthwards.blueplaqueslondon.activities.PanoramaActivity has leaked:
* GC ROOT thread com.google.maps.api.android.lib6.gmm6.streetview.bf.v (named 'Renderer')
* references com.google.maps.api.android.lib6.gmm6.streetview.f.mParent
* references android.widget.FrameLayout.mParent
* references android.widget.FrameLayout.mContext
* leaks com.upwardsnorthwards.blueplaqueslondon.activities.PanoramaActivity instance
* Reference Key: 9d5d97cd-865a-4f93-92c1-63f7a8589525
* Device: motorola motorola XT1021 condor_tescogb
* Android Version: 4.4.4 API: 19
* Durations: watch=5024ms, gc=236ms, heap dump=745ms, analysis=39070ms
PanoramaActivity
导致这种情况的方法onCreate
如下所示:
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_panorama);
final StreetViewPanoramaFragment streetViewPanoramaFragment =
(StreetViewPanoramaFragment) getFragmentManager()
.findFragmentById(R.id.street_view_panorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(this);
final Intent intent = getIntent();
if (intent != null) {
placemark = (Placemark) intent
.getParcelableExtra(BluePlaquesConstants.PANORAMA_CLICKED_PARCLEABLE_KEY);
}
}
此活动的 .xml 布局文件如下所示:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/street_view_panorama"
android:name="com.google.android.gms.maps.StreetViewPanoramaFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我的项目的 gradle 文件如下所示:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.github.hotchemi:android-rate:0.4.2'
compile 'com.squareup:otto:1.3.6'
}
该应用程序的完整源代码可在https://github.com/seanoshea/BluePlaquesLondon-Android获得,我在 https://github.com/seanoshea/BluePlaquesLondon-Android/issues/69 创建了一个问题来跟踪它.
有没有其他人遇到过这个问题?您能否提出解决方案?
干杯,
肖恩