内存不足的错误时,使用谷歌地图API [英] Out of memory error when using Google Maps API

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

问题描述

我这里有一个应用程序,具有显示在地图上的POI的特征。它只有一个兴趣点时,它的实际的可见区域内它只能绘制。它完美一段时间,但如果我玩放大和缩小并拖动,它最终会崩溃。据logcat的,其原因始终是一个内存溢出错误。

起初,我还以为是在谷歌地图API的错误。经过一番研究,看到一些罗曼盖伊的帖子,我是那种相信,我做了一些愚蠢的事在我的应用程序,让我耗尽内存不时。 然后我跑了堆在分析仪(Eclipse的)一些更详细的测试,我发现即使我有2+,有时3+ MB可用内存留,我仍然得到造成的OutOfMemoryError那些烦人的强制关闭的消息。大多数试图分配的内存部分614KB块不管多少我已经离开,当它崩溃的时代。

此问题发生了很多的Nexus One 2.2.1和HTC的Evo 2.1。经过一些小测试,我没有崩溃既不G1 1.6也不是三星Galaxy S I9000 2.1。但我不能肯定地说在G1和经过测试的银河不会出现这个问题。

我只能想到的内存碎片问题。我希望这个问题有一个解决方案。我也很高兴,如果我能正好赶上这个错误,prevent应用程序崩溃。

如果有帮助,这里的logcat的:

 八月九号至29日:58:06.661:ERROR / dalvikvm堆(1552):648000字节的外部分配太大,此过程。
八月九日至29号:58:06.661:ERROR / dalvikvm(1552):内存:堆大小= 9991KB,分配= 6980KB,位图大小= 14510KB
八月九日至29号:58:06.661:ERROR /(1552):虚拟机不会让我们分配648000字节
八月九日至29号:58:06.672:DEBUG / AndroidRuntime(1552):关闭虚拟机
八月九日至29号:58:06.672:WARN / dalvikvm(1552):主题ID = 3:线程退出与未捕获的异常(组= 0x4001b390)
八月九日至29号:58:06.672:ERROR / AndroidRuntime(1552):未捕获的处理程序:螺纹主力退出,由于未捕获的异常
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):java.lang.OutOfMemoryError:位图大小超过VM预算
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.graphics.Bitmap.nativeCreate(本机方法)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.graphics.Bitmap.createBitmap(Bitmap.java:569)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.google.android.maps.ZoomHelper.createSnapshot(ZoomHelper.java:422)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.google.android.maps.ZoomHelper.beginZoom(ZoomHelper.java:186)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.google.android.maps.MapView $ 2.onScaleBegin(MapView.java:371)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.view.ScaleGestureDetector.onTouchEvent(ScaleGestureDetector.java:208)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.google.android.maps.MapView.onTouchEvent(MapView.java:646)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.view.View.dispatchTouchEvent(View.java:3709)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1701)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.app.Activity.dispatchTouchEvent(Activity.java:2068)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1685)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.view.ViewRoot.handleMessage(ViewRoot.java:1708)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.os.Handler.dispatchMessage(Handler.java:99)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.os.Looper.loop(Looper.java:123)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在android.app.ActivityThread.main(ActivityThread.java:4595)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在java.lang.reflect.Method.invokeNative(本机方法)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在java.lang.reflect.Method.invoke(Method.java:521)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
八月九日至29号:58:06.681:ERROR / AndroidRuntime(1552):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

我一直有这个完全相同的问题,我腌code一些System.GC的呼吁,它似乎一点点帮助,但是这仍然发生。

我也获得另一个问题,这可能与那里的地图似乎转出,全力以赴随机,当你捏缩放。这往往会崩溃之前,有时会发生。

这是所有仅只能在HTC Desire的,我相信是同一部手机的Nexus One的引擎盖下发生的。 (在许多方面与EVO其中还患有它相似)。

注意:这是工作100%的罚款我们的弧S,银河V1,AVD模拟器和华​​硕平板电脑

I have an application here that has a feature of showing a POI on the map. It's only one POI and it is only drawn when it's actually within the visible screen area. It works perfectly for a while but if I play around zooming in and out and dragging, it will eventually crash. According to Logcat, the reason is always an OutOfMemory error.

At first, I thought it was a bug on the Google Maps API. After some researching and seeing some Romain Guy posts, I was kind of convinced that I had done something stupid on my app that kept me running out of memory from time to time. Then I ran some more detailed tests with Heap Analyzer (Eclipse) on and I saw that even though I had 2+, sometimes 3+ megabytes left of free memory, I was still getting those annoying Force Close messages caused by OutOfMemoryError. Most of the times it crashes when trying to allocate some 614kb chunk of memory regardless of how much I have left.

This problem happens a lot on Nexus One 2.2.1 and on HTC Evo 2.1. After some little testing, I got no crash neither on G1 1.6 nor Samsung Galaxy S i9000 2.1. But I cannot say for sure the G1 and Galaxy will not show this problem after more testing.

I can only think of a memory fragmentation problem. I hope this problem has a solution. I will also be glad if I can just catch this error and prevent the app from crashing.

If it helps, here's the logcat:

09-29 08:58:06.661: ERROR/dalvikvm-heap(1552): 648000-byte external allocation too large for this process.
09-29 08:58:06.661: ERROR/dalvikvm(1552): Out of memory: Heap Size=9991KB, Allocated=6980KB, Bitmap Size=14510KB
09-29 08:58:06.661: ERROR/(1552): VM won't let us allocate 648000 bytes
09-29 08:58:06.672: DEBUG/AndroidRuntime(1552): Shutting down VM
09-29 08:58:06.672: WARN/dalvikvm(1552): threadid=3: thread exiting with uncaught exception (group=0x4001b390)
09-29 08:58:06.672: ERROR/AndroidRuntime(1552): Uncaught handler: thread main exiting due to uncaught exception
09-29 08:58:06.681: ERROR/AndroidRuntime(1552): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.graphics.Bitmap.nativeCreate(Native Method)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.graphics.Bitmap.createBitmap(Bitmap.java:569)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.google.android.maps.ZoomHelper.createSnapshot(ZoomHelper.java:422)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.google.android.maps.ZoomHelper.beginZoom(ZoomHelper.java:186)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.google.android.maps.MapView$2.onScaleBegin(MapView.java:371)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.view.ScaleGestureDetector.onTouchEvent(ScaleGestureDetector.java:208)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:646)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.view.View.dispatchTouchEvent(View.java:3709)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1701)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1685)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1708)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.os.Looper.loop(Looper.java:123)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at android.app.ActivityThread.main(ActivityThread.java:4595)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at java.lang.reflect.Method.invokeNative(Native Method)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at java.lang.reflect.Method.invoke(Method.java:521)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-29 08:58:06.681: ERROR/AndroidRuntime(1552):     at dalvik.system.NativeStart.main(Native Method)

解决方案

I have been having this EXACT same problem, I salted the code with some System.GC calls and it seemed to help a little bit, but this still happens.

I am also getting another problem which might be related where the map seems to flip out and go all random when you pinch zoom. This tends to happen sometimes before a crash.

This is all only happening only on an HTC Desire which I believe is the same phone as the Nexus One under the hood. (and similar in many ways to the EVO which also suffers from it).

Note: It is working 100% fine on our Arc-S, Galaxy V1, AVD emulator and Asus tablet.

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

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