MapFragment谷歌地图API第2版内存不足错误/内存泄漏 [英] MapFragment Google Maps API v2 Out of Memory Error / Memory Leak

查看:237
本文介绍了MapFragment谷歌地图API第2版内存不足错误/内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过一些在过去几天类似的帖子,但没有专门回答这个问题。我开始〜2分钟的侵略性地图平移后得到一个OOM问题,并与混合地图缩放。该应用程序也似乎守住崩溃后的内存,因为它需要较少的第一次失败后达到OOM时间。我缩小了code只是一个MapFragment的活动,并仍然得到同样的OOM。我用DDMS和MAT,试图找出问题,除了加入安卓largeHeap =真正的只延迟OOM。屏幕重新定位不是一个问题,因为我设置安卓screenOrientation =画像在我的清单。任何帮助将是AP preciated。

更新2014年8月25日:据说这是2013年5月被固定了?

更新2014年9月6日:仍然没有成功,唯一的好选项是使用正常,而不是混合。 GC似乎能够跟上没有图像。

类似的帖子:

<一个href="http://stackoverflow.com/questions/3819492/out-of-memory-error-when-using-google-maps-api/25555595#25555595">Out内存不足的错误时,使用谷歌地图API

<一个href="http://stackoverflow.com/questions/16022897/memory-leak-for-android-google-maps-api-v2?lq=1">Memory泄漏Android版谷歌地图API V2

<一个href="http://stackoverflow.com/questions/22049925/android-google-maps-api-outofmemoryerror?rq=1">Android谷歌地图API,OutOfMemoryError异常

MainActivity:

 公共类MainActivity_blank延伸活动{

GoogleMap的MMAP;


@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main_activity_blank);
    的setContentView(R.layout.map_fragment);

     setUpMapIfNeeded();

}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    //充气菜单;这增加了项目操作栏,如果它是present。
    。getMenuInflater()膨胀(R.menu.main_activity_blank,菜单);
    返回true;
}

@覆盖
公共布尔onOptionsItemSelected(菜单项项){
    //处理动作栏项目点击这里。将操作栏
    //自动在主/向上按钮操作的点击,只要
    //你在AndroidManifest.xml中指定一个父活动。
    INT的id = item.getItemId();
    如果(ID == R.id.action_settings){
        返回true;
    }
    返回super.onOptionsItemSelected(项目);
}

私人无效setUpMapIfNeeded(){
    //做一个空检查确认,我们还没有实例化的地图。
    如果(MMAP == NULL){
        MMAP =((MapFragment)getFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
        //检查如果我们成功取得地图。
        如果(MMAP!= NULL){
            //地图进行验证。现在可以安全操控地图。
            // startUsingMap();
            mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        }
    }
}
}
 

logcat的:

  08-26 17:15:29.302:I / dalvikvm堆(19642):强制收集SoftReferences为67108880个字节分配
08-26 17:15:29.372:D / dalvikvm(19642):GC_BEFORE_OOM释放822K,65%免费37523K / 106080K,暂停78ms,共78ms
08-26 17:15:30.582:W / dalvikvm(19642):块太大传送(长度= 49579336,48435字节)
08-26 17:15:31.532:E / dalvikvm堆(19642):内存在67108880字节分配。
08-26 17:15:31.532:I / dalvikvm(19642):GLThread 14876PRIO = 5 TID = 19 RUNNABLE
08-26 17:15:31.532:I / dalvikvm(19642):|组=主SCOUNT = 0 dsCount = 0的obj = 0x42c120d8自我= 0x787e8438
08-26 17:15:31.532:I / dalvikvm(19642):| sysTid = 19729漂亮= 1 sched的= 0/0 CGRP =应用程序处理= 2021558416
08-26 17:15:31.532:I / dalvikvm(19642):|状态= R schedstat =(51120733635 13119596807 80537)UTM = 1904年STM = 3208核心= 0
08-26 17:15:31.532:I / dalvikvm(19642):在android.graphics.Bitmap.nativeCreate(本机方法)
08-26 17:15:31.532:I / dalvikvm(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:924)
08-26 17:15:31.532:I / dalvikvm(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:901)
08-26 17:15:31.532:I / dalvikvm(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:868)
08-26 17:15:31.532:I / dalvikvm(19642):在opl.a((空): -  1)
08-26 17:15:31.532:I / dalvikvm(19642):在okg.a((空): -  1)
08-26 17:15:31.532:I / dalvikvm(19642):在opy.a((空): -  1)
08-26 17:15:31.532:I / dalvikvm(19642):在opx.a((空): -  1)
08-26 17:15:31.532:I / dalvikvm(19642):在ojx.a((空): -  1)
08-26 17:15:31.532:I / dalvikvm(19642):在ojx.b((空): -  1)
08-26 17:15:31.532:I / dalvikvm(19642):在otq.k((空): -  1)
08-26 17:15:31.532:I / dalvikvm(19642):在otq.run((空): -  1)
08-26 17:15:31.542:W / System.err的(19642):内存不足
08-26 17:15:31.642:D / dalvikvm(19642):GC_EXPLICIT释放4803K,64%免费38238K / 106080K,暂停6ms的+ 11毫秒,总102ms
08-26 17:15:32.822:W / dalvikvm(19642):块太大传送(长度= 49444016,48303字节)
08-26 17:15:33.682:D / dalvikvm(19642):GC_FOR_ALLOC释放3728K,66%免费36916K / 106080K,暂停为65μs,共为65μs
08-26 17:15:34.752:W / dalvikvm(19642):块太大传送(长度= 49398928,48259字节)
08-26 17:15:35.462:I / dalvikvm堆(19642):强制收集SoftReferences为67108880个字节分配
08-26 17:15:35.512:D / dalvikvm(19642):GC_BEFORE_OOM释放413K,66%免费36502K / 106080K,暂停52ms,共52ms
08-26 17:15:36.742:W / dalvikvm(19642):块太大传送(长度= 49398928,48259字节)
08-26 17:15:37.282:E / dalvikvm堆(19642):内存在67108880字节分配。
08-26 17:15:37.282:I / dalvikvm(19642):GLThread 14876PRIO = 5 TID = 19 RUNNABLE
08-26 17:15:37.282:I / dalvikvm(19642):|组=主SCOUNT = 0 dsCount = 0的obj = 0x42c120d8自我= 0x787e8438
08-26 17:15:37.282:I / dalvikvm(19642):| sysTid = 19729漂亮= 1 sched的= 0/0 CGRP =应用程序处理= 2021558416
08-26 17:15:37.282:I / dalvikvm(19642):|状态= R schedstat =(54770836691 14106993077 84458)UTM = 1996 STM = 3481核心= 0
08-26 17:15:37.282:I / dalvikvm(19642):在android.graphics.Bitmap.nativeCreate(本机方法)
08-26 17:15:37.282:I / dalvikvm(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:924)
08-26 17:15:37.282:I / dalvikvm(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:901)
08-26 17:15:37.282:I / dalvikvm(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:868)
08-26 17:15:37.282:I / dalvikvm(19642):在opl.a((空): -  1)
08-26 17:15:37.282:I / dalvikvm(19642):在okg.a((空): -  1)
08-26 17:15:37.282:I / dalvikvm(19642):在opy.a((空): -  1)
08-26 17:15:37.282:I / dalvikvm(19642):在opx.a((空): -  1)
08-26 17:15:37.282:I / dalvikvm(19642):在ojx.a((空): -  1)
08-26 17:15:37.282:I / dalvikvm(19642):在ojx.b((空): -  1)
08-26 17:15:37.282:I / dalvikvm(19642):在otq.k((空): -  1)
08-26 17:15:37.282:I / dalvikvm(19642):在otq.run((空): -  1)
08-26 17:15:37.432:W / dalvikvm(19642):主题ID = 19:线程退出与未捕获的异常(组= 0x4178cda0)
08-26 17:15:37.442:E / AndroidRuntime(19642):致命异常:GLThread 14876
08-26 17:15:37.442:E / AndroidRuntime(19642):工艺:com.example.maptest,PID:19642
08-26 17:15:37.442:E / AndroidRuntime(19642):java.lang.OutOfMemoryError
08-26 17:15:37.442:E / AndroidRuntime(19642):在android.graphics.Bitmap.nativeCreate(本机方法)
08-26 17:15:37.442:E / AndroidRuntime(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:924)
08-26 17:15:37.442:E / AndroidRuntime(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:901)
08-26 17:15:37.442:E / AndroidRuntime(19642):在android.graphics.Bitmap.createBitmap(Bitmap.java:868)
08-26 17:15:37.442:E / AndroidRuntime(19642):在opl.a(来源不明)
08-26 17:15:37.442:E / AndroidRuntime(19642):在okg.a(来源不明)
08-26 17:15:37.442:E / AndroidRuntime(19642):在opy.a(来源不明)
08-26 17:15:37.442:E / AndroidRuntime(19642):在opx.a(来源不明)
08-26 17:15:37.442:E / AndroidRuntime(19642):在ojx.a(来源不明)
08-26 17:15:37.442:E / AndroidRuntime(19642):在ojx.b(来源不明)
08-26 17:15:37.442:E / AndroidRuntime(19642):在otq.k(来源不明)
08-26 17:15:37.442:E / AndroidRuntime(19642):在otq.run(来源不明)
08-26 17:15:37.522:D / AbsListView(19642):unregisterIRListener()被调用
08-26 17:15:38.092:D / AbsListView(19642):onDetachedFromWindow
08-26 17:15:38.092:D / AbsListView(19642):unregisterIRListener()被调用
08-26 17:15:38.102:D / AbsListView(19642):onVisibilityChanged()被调用时,可见性:8
08-26 17:15:38.102:D / AbsListView(19642):unregisterIRListener()被调用
 

解决方案

尝试调用地图的onPause,onResume,onLowMemory相应片段的方法。

I've read a number of similar posts over the past few days, but none that specifically answer this problem. I start getting an OOM issue after ~2 minutes of aggressive map panning and zooming with the Hybrid map. The app also seems to hold onto the memory after the crash because it takes less time to reach OOM after the first failure. I scaled down the code to just an Activity with a MapFragment and still get the same OOM. I've used DDMS and MAT to try and isolate the problem, in addition to adding android:largeHeap="true" which only delays the OOM. Screen re-orientation is not an issue because I'm setting android:screenOrientation="portrait" in my Manifest. Any help would be appreciated.

Update 2014-08-25: This is supposed to be fixed back in May 2013?

Update 2014-09-06: Still no success, the only good option is to use Normal instead of Hybrid. GC seems to be able to keep up without the imagery.

Similar Posts:

Out of memory error when using Google Maps API

Memory leak for Android Google Maps API v2

Android Google maps API, OutOfMemoryError

MainActivity:

public class MainActivity_blank extends Activity {

GoogleMap mMap;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main_activity_blank);
    setContentView(R.layout.map_fragment);

     setUpMapIfNeeded();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_activity_blank, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            // The Map is verified. It is now safe to manipulate the map.
            //startUsingMap();
            mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        }
    }
}
}

logcat:

08-26 17:15:29.302: I/dalvikvm-heap(19642): Forcing collection of SoftReferences for 67108880-byte allocation
08-26 17:15:29.372: D/dalvikvm(19642): GC_BEFORE_OOM freed 822K, 65% free 37523K/106080K, paused 78ms, total 78ms
08-26 17:15:30.582: W/dalvikvm(19642): chunk is too big to transmit (length=49579336, 48435 bytes)
08-26 17:15:31.532: E/dalvikvm-heap(19642): Out of memory on a 67108880-byte allocation.
08-26 17:15:31.532: I/dalvikvm(19642): "GLThread 14876" prio=5 tid=19 RUNNABLE
08-26 17:15:31.532: I/dalvikvm(19642):   | group="main" sCount=0 dsCount=0 obj=0x42c120d8 self=0x787e8438
08-26 17:15:31.532: I/dalvikvm(19642):   | sysTid=19729 nice=1 sched=0/0 cgrp=apps handle=2021558416
08-26 17:15:31.532: I/dalvikvm(19642):   | state=R schedstat=( 51120733635 13119596807 80537 ) utm=1904 stm=3208 core=0
08-26 17:15:31.532: I/dalvikvm(19642):   at android.graphics.Bitmap.nativeCreate(Native Method)
08-26 17:15:31.532: I/dalvikvm(19642):   at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
08-26 17:15:31.532: I/dalvikvm(19642):   at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
08-26 17:15:31.532: I/dalvikvm(19642):   at android.graphics.Bitmap.createBitmap(Bitmap.java:868)
08-26 17:15:31.532: I/dalvikvm(19642):   at opl.a((null):-1)
08-26 17:15:31.532: I/dalvikvm(19642):   at okg.a((null):-1)
08-26 17:15:31.532: I/dalvikvm(19642):   at opy.a((null):-1)
08-26 17:15:31.532: I/dalvikvm(19642):   at opx.a((null):-1)
08-26 17:15:31.532: I/dalvikvm(19642):   at ojx.a((null):-1)
08-26 17:15:31.532: I/dalvikvm(19642):   at ojx.b((null):-1)
08-26 17:15:31.532: I/dalvikvm(19642):   at otq.k((null):-1)
08-26 17:15:31.532: I/dalvikvm(19642):   at otq.run((null):-1)
08-26 17:15:31.542: W/System.err(19642): OutOfMemory
08-26 17:15:31.642: D/dalvikvm(19642): GC_EXPLICIT freed 4803K, 64% free 38238K/106080K, paused 6ms+11ms, total 102ms
08-26 17:15:32.822: W/dalvikvm(19642): chunk is too big to transmit (length=49444016, 48303 bytes)
08-26 17:15:33.682: D/dalvikvm(19642): GC_FOR_ALLOC freed 3728K, 66% free 36916K/106080K, paused 65ms, total 65ms
08-26 17:15:34.752: W/dalvikvm(19642): chunk is too big to transmit (length=49398928, 48259 bytes)
08-26 17:15:35.462: I/dalvikvm-heap(19642): Forcing collection of SoftReferences for 67108880-byte allocation
08-26 17:15:35.512: D/dalvikvm(19642): GC_BEFORE_OOM freed 413K, 66% free 36502K/106080K, paused 52ms, total 52ms
08-26 17:15:36.742: W/dalvikvm(19642): chunk is too big to transmit (length=49398928, 48259 bytes)
08-26 17:15:37.282: E/dalvikvm-heap(19642): Out of memory on a 67108880-byte allocation.
08-26 17:15:37.282: I/dalvikvm(19642): "GLThread 14876" prio=5 tid=19 RUNNABLE
08-26 17:15:37.282: I/dalvikvm(19642):   | group="main" sCount=0 dsCount=0 obj=0x42c120d8 self=0x787e8438
08-26 17:15:37.282: I/dalvikvm(19642):   | sysTid=19729 nice=1 sched=0/0 cgrp=apps handle=2021558416
08-26 17:15:37.282: I/dalvikvm(19642):   | state=R schedstat=( 54770836691 14106993077 84458 ) utm=1996 stm=3481 core=0
08-26 17:15:37.282: I/dalvikvm(19642):   at android.graphics.Bitmap.nativeCreate(Native Method)
08-26 17:15:37.282: I/dalvikvm(19642):   at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
08-26 17:15:37.282: I/dalvikvm(19642):   at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
08-26 17:15:37.282: I/dalvikvm(19642):   at android.graphics.Bitmap.createBitmap(Bitmap.java:868)
08-26 17:15:37.282: I/dalvikvm(19642):   at opl.a((null):-1)
08-26 17:15:37.282: I/dalvikvm(19642):   at okg.a((null):-1)
08-26 17:15:37.282: I/dalvikvm(19642):   at opy.a((null):-1)
08-26 17:15:37.282: I/dalvikvm(19642):   at opx.a((null):-1)
08-26 17:15:37.282: I/dalvikvm(19642):   at ojx.a((null):-1)
08-26 17:15:37.282: I/dalvikvm(19642):   at ojx.b((null):-1)
08-26 17:15:37.282: I/dalvikvm(19642):   at otq.k((null):-1)
08-26 17:15:37.282: I/dalvikvm(19642):   at otq.run((null):-1)
08-26 17:15:37.432: W/dalvikvm(19642): threadid=19: thread exiting with uncaught exception (group=0x4178cda0)
08-26 17:15:37.442: E/AndroidRuntime(19642): FATAL EXCEPTION: GLThread 14876
08-26 17:15:37.442: E/AndroidRuntime(19642): Process: com.example.maptest, PID: 19642
08-26 17:15:37.442: E/AndroidRuntime(19642): java.lang.OutOfMemoryError
08-26 17:15:37.442: E/AndroidRuntime(19642):    at android.graphics.Bitmap.nativeCreate(Native Method)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at android.graphics.Bitmap.createBitmap(Bitmap.java:868)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at opl.a(Unknown Source)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at okg.a(Unknown Source)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at opy.a(Unknown Source)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at opx.a(Unknown Source)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at ojx.a(Unknown Source)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at ojx.b(Unknown Source)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at otq.k(Unknown Source)
08-26 17:15:37.442: E/AndroidRuntime(19642):    at otq.run(Unknown Source)
08-26 17:15:37.522: D/AbsListView(19642): unregisterIRListener() is called 
08-26 17:15:38.092: D/AbsListView(19642): onDetachedFromWindow
08-26 17:15:38.092: D/AbsListView(19642): unregisterIRListener() is called 
08-26 17:15:38.102: D/AbsListView(19642): onVisibilityChanged() is called, visibility : 8
08-26 17:15:38.102: D/AbsListView(19642): unregisterIRListener() is called

解决方案

try call map onPause, onResume, onLowMemory in corresponding Fragment methods.

这篇关于MapFragment谷歌地图API第2版内存不足错误/内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆