我正努力解决v2的内存泄漏问题。每次在以下情况下,当我的视图再次可见时,堆的使用率将增加约85 my:
该应用程序最终与一个OutOfMemory异常崩溃。泄漏不发生在屏幕旋转,或退出时,“后退”按钮。对解决办法有什么想法吗?或者这个问题背后的原因?
我的代码:
public class LeakActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_leak);
}
}和XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>发布于 2013-05-03 10:17:38
这可能与Maps API中的这个未决问题有关:
问题4766 - Bug: v2泄露了大量内存
使用DDMS的“转储HPROF”工具转储hprof文件,用hprof-conv转换它,并使用垫子检查泄漏。如果它在Google中,请将apk (或更好的简单测试代码)发布到未公开的问题上,并包含hprof文件。
如果这是我正在经历的相同的错误,它可能只发生在Android2.x上,请也检查一下。
发布于 2013-06-06 07:21:14
在初始化映射之前,我尝试使用System.gc()和map.clear()。
@Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS) {
System.gc();
getMap().clear();
setupmap();
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
System.gc();
}https://stackoverflow.com/questions/16022897
复制相似问题