title: Out of memory error when using Google Maps API
body: <p>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.</p>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>If it helps, here's the logcat:</p>
  
  <pre><code>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)
  </code></pre>