Out of memory error when using Google Maps API - android

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 running into this problem on and off for the past month. The way I've worked around the issue in my code is by forcing the GC to clean up unreferenced bitmaps that I have wrapped in WeakReferences. This approach might not work for you since the crash that you pasted above seems to originate in the MapView. Regardless, try to sprinkle some System.gc() calls in key locations in your code and watch the system Log to see if the GC_EXPLICIT messages indicate a lot of objects/bytes freed. In the code I'm working on I've had to add a System.gc() at the end of my Adapter.getView() method to ensure that unused bitmaps are cleaned up by the next time getView() is called. This approach seems to have drastically reduced my run in with the
dreaded java.lang.OutOfMemoryError: bitmap size exceeds VM budget crash.

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.

I had the same problem , add the following line in manifest file under application tag
android:largeHeap = true . This worked for me

Related

Android KitKat 4.4 Chromium WebView "v8_value_converter_impl.cc" error

I am building an Android app which contains a couple of webview. The app needs to support KitKat 4.4 at minimum which embeds chromium v30 webview according to this. I am testing the app on Samsung Galaxy Note 2 running 4.4.2 stock rom, the webview runs very slowly and the logcat is flood with the below error messages:
...
03-21 14:11:48.651 29445-29445/com.mylovely.app I/GraphicBuffer: allocate buffer (w:384 h:384 f:1) handle(0x6f64b600) err(0)
03-21 14:11:48.652 29445-29445/com.mylovely.app I/GraphicBuffer: allocate buffer (w:384 h:384 f:1) handle(0x6d715280) err(0)
03-21 14:11:48.652 29445-29445/com.mylovely.app I/GraphicBuffer: allocate buffer (w:128 h:192 f:1) handle(0x6dd99590) err(0)
03-21 14:12:03.996 29445-29884/com.mylovely.app E/chromium: [ERROR:v8_value_converter_impl.cc(405)] Getter for property selectionDirection threw an exception.
03-21 14:12:03.996 29445-29884/com.mylovely.app E/chromium: [ERROR:v8_value_converter_impl.cc(405)] Getter for property selectionEnd threw an exception.
03-21 14:12:03.996 29445-29884/com.mylovely.app E/chromium: [ERROR:v8_value_converter_impl.cc(405)] Getter for property selectionStart threw an exception.
03-21 14:12:04.007 29445-29884/com.mylovely.app E/chromium: [ERROR:v8_value_converter_impl.cc(405)] Getter for property selectionDirection threw an exception.
03-21 14:12:04.007 29445-29884/com.mylovely.app E/chromium: [ERROR:v8_value_converter_impl.cc(405)] Getter for property selectionEnd threw an exception.
03-21 14:12:04.007 29445-29884/com.mylovely.app E/chromium: [ERROR:v8_value_converter_impl.cc(405)] Getter for property selectionStart threw an exception.
... <skipped lots of duplicated error here>
03-21 14:12:05.370 29445-29445/com.mylovely.app I/dalvikvm-heap: Grow heap (frag case) to 41.055MB for 11211498-byte allocation
03-21 14:12:06.285 29445-29445/com.mylovely.app I/dalvikvm-heap: Grow heap (frag case) to 34.448MB for 4285074-byte allocation
03-21 14:12:06.354 29445-29445/com.mylovely.app I/Choreographer: Skipped 41 frames! The application may be doing too much work on its main thread.
03-21 14:12:06.356 29445-29445/com.mylovely.app I/GraphicBuffer: allocate buffer (w:384 h:384 f:1) handle(0x637baab0) err(0)
03-21 14:12:06.358 29445-29445/com.mylovely.app I/GraphicBuffer: allocate buffer (w:384 h:384 f:1) handle(0x6e7ee640) err(0)
...
I already did some googling and found this seems to be fixed this chromium ticket. But since we cannot update the system webview under 4.4.2 through Google Play. Is there any other way to fix / workaround this issue beside embedding other webview (like crosswalk) to the app?
I found out the root cause of the issue. I added some heavy js tasks in the onProgressChanged callback, which they would output an null object. This null object could not be serialized and causing the bug in this chromium ticket. As a workaround, I wrapped all the js calls with IIFE to slient the output and throttle the js calls in onProgressChanged using Guava's RateLimiter.

Android AVD emulator not running app, but device does? (OpenGL)

Hi I am trying to run some sample openGl code on an emulator. I am new to Android development. It crashes on the emulator but not my device, a Samsung Galaxy Note phone N7000.
The AVD settings I tried were:
Target: Android 4.1 - API Level 16
CPU/ABI: ARM (armeabi-v7a)
SD Card: 32 MiB
Skin: Built-in : WGA800
Here are the errors on the console:
10-15 13:23:34.287: E/Trace(621): error opening trace file: No such file or directory (2)
10-15 13:23:34.848: D/libEGL(621): Emulator without GPU support detected. Fallback to software renderer.
10-15 13:23:34.878: D/libEGL(621): loaded /system/lib/egl/libGLES_android.so
10-15 13:23:34.947: D/gralloc_goldfish(621): Emulator without GPU emulation detected.
10-15 13:23:34.977: W/dalvikvm(621): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
10-15 13:23:34.977: E/AndroidRuntime(621): FATAL EXCEPTION: GLThread 72
10-15 13:23:34.977: E/AndroidRuntime(621): java.lang.IllegalArgumentException: No configs match configSpec
10-15 13:23:34.977: E/AndroidRuntime(621): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:863)
10-15 13:23:34.977: E/AndroidRuntime(621): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
10-15 13:23:34.977: E/AndroidRuntime(621): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
10-15 13:23:34.977: E/AndroidRuntime(621): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
10-15 13:23:35.377: I/Choreographer(621): Skipped 67 frames! The application may be doing too much work on its main thread.
10-15 13:23:36.658: I/Choreographer(621): Skipped 72 frames! The application may be doing too much work on its main thread.
Thanks
Bob
10-15 13:23:34.848: D/libEGL(621): Emulator without GPU support detected. Fallback to software renderer.
Just recreate or edit your emulator and be sure that under the hardware list you have
GPU Emulation set to Yes

image is not a power of 2?

So, i've made the raindrop tutorial project by libGDX. However, when i attempt to deploy it to the emulator i get an error saying that the image is not a power of 2. But i did re-size the images to be 48X48 using GIMP (as the tutorial had suggested). I believe he had added in some code to ensure that it would be possible to add in images that were not necessarily a power of two?
Does anyone know how i would fix this? Making it a power of two is a bit limiting.. isn't it? I followed the tutorial very closely! So... i'm not sure where to go from here. Noob at libGDX.
LogCat Dump:
06-11 00:22:50.942: W/dalvikvm(545): threadid=11: thread exiting with uncaught exception (group=0x409c01f8)
06-11 00:22:50.952: E/AndroidRuntime(545): FATAL EXCEPTION: GLThread 72
06-11 00:22:50.952: E/AndroidRuntime(545): com.badlogic.gdx.utils.GdxRuntimeException: Texture width and height must be powers of two: 48x48
06-11 00:22:50.952: E/AndroidRuntime(545): at com.badlogic.gdx.graphics.Texture.uploadImageData(Texture.java:197)
06-11 00:22:50.952: E/AndroidRuntime(545): at com.badlogic.gdx.graphics.Texture.load(Texture.java:179)
06-11 00:22:50.952: E/AndroidRuntime(545): at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
06-11 00:22:50.952: E/AndroidRuntime(545): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
06-11 00:22:50.952: E/AndroidRuntime(545): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122)
06-11 00:22:50.952: E/AndroidRuntime(545): at com.badlogic.drop.Drop.create(Drop.java:38)
06-11 00:22:50.952: E/AndroidRuntime(545): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:292)
06-11 00:22:50.952: E/AndroidRuntime(545): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1455)
06-11 00:22:50.952: E/AndroidRuntime(545): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
06-11 00:22:51.041: I/AndroidInput(545): sensor listener tear down
06-11 00:22:51.041: I/AndroidGraphics(545): Managed meshes/app: { }
06-11 00:22:51.041: I/AndroidGraphics(545): Managed textures/app: { }
06-11 00:22:51.041: I/AndroidGraphics(545): Managed shaders/app: { }
06-11 00:22:51.041: I/AndroidGraphics(545): Managed buffers/app: { }
48x48 is not a power of two. The app requires OpenGL ES 2.0 as stated in the text. The standard emulator only runs OpenGL ES 1.0. You can rescale the image to 32x32, then everything will work as expected on OpenGL ES 1.x as well.
I'd recommend not using the emulator for testing OpenGL ES apps. Use a real device instead.
You can stop it from enforcing the power of two requirement by setting the following line of code in your game class in the create() method:
Texture.setEnforcePotImages(false);
this worked for me
change all "GL10" imported from "com.badlogic.gdx.graphics.GL10" to "GL20" imported from "com.badlogic.gdx.graphics.GL20"

Memory error in Android after capturing images

In my Android application I'm trying to capture three images and upload this three images. I'm capturing two images one by one no problem but when I capture third images the application crashes with error:
09-26 16:17:31.398: ERROR/AndroidRuntime(24115): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-26 16:17:31.398: ERROR/AndroidRuntime(24115): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
09-26 16:17:31.398: ERROR/AndroidRuntime(24115): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
09-26 16:17:31.398: ERROR/AndroidRuntime(24115): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:271)
09-26 16:17:31.398: ERROR/AndroidRuntime(24115): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:296)
How can I solve the error like this?

Android Hello World app crashes: IllegalArgumentException from Surface.lockCanvasNative

I am trying to run the simplest Hello World example app and looks like I can crash it even all it does is showing a TextView.
Steps to reproduce: Launch it in the emulator (1.5). Open the app - it shows the text view, then lock the phone by pressing "end call" button. Unlock by pressing "menu", then press "back". App crashes with "The process android.process.acore has stopped unexpectedly..." and Force Close button. It does not happen all the time, but I am able to reproduce it every time after wiping the user data at least.
I wonder if default Hello World is missing a detail which was considered too advanced for a hello world... Such problems with a basic example does not look very encouraging =)
Any idea what detail is missing and how to avoid this crash?
Stack (I've truncated timestamps):
37.478: DEBUG/KeyguardViewMediator(576): wakeWhenReadyLocked(82)
37.481: DEBUG/KeyguardViewMediator(576): handleWakeWhenReady(82)
37.481: DEBUG/KeyguardViewMediator(576): pokeWakelock(5000)
39.110: DEBUG/KeyguardViewMediator(576): pokeWakelock(5000)
39.140: WARN/InputManagerService(576): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#436e3fc0
40.990: ERROR/IMemory(679): binder=0x238aa8 transaction failed fd=-2147483647, size=0, err=-2147483646 (Unknown error: 2147483646)
40.990: ERROR/IMemory(679): cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
40.990: ERROR/IMemory(679): cannot map BpMemoryHeap (binder=0x238aa8), size=0, fd=-1 (Bad file number)
40.990: ERROR/Surface(679): Couldn't map Surface's heap (binder=0x238aa8, heap=0x238b00)
40.990: DEBUG/AndroidRuntime(679): Shutting down VM
40.990: WARN/dalvikvm(679): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
40.990: ERROR/AndroidRuntime(679): Uncaught handler: thread main exiting due to uncaught exception
40.990: ERROR/AndroidRuntime(679): java.lang.IllegalArgumentException
40.990: ERROR/AndroidRuntime(679): at android.view.Surface.lockCanvasNative(Native Method)
40.990: ERROR/AndroidRuntime(679): at android.view.Surface.lockCanvas(Surface.java:196)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.draw(ViewRoot.java:1175)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.performTraversals(ViewRoot.java:1030)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
40.990: ERROR/AndroidRuntime(679): at android.os.Handler.dispatchMessage(Handler.java:99)
40.990: ERROR/AndroidRuntime(679): at android.os.Looper.loop(Looper.java:123)
40.990: ERROR/AndroidRuntime(679): at android.app.ActivityThread.main(ActivityThread.java:3948)
40.990: ERROR/AndroidRuntime(679): at java.lang.reflect.Method.invokeNative(Native Method)
40.990: ERROR/AndroidRuntime(679): at java.lang.reflect.Method.invoke(Method.java:521)
40.990: ERROR/AndroidRuntime(679): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
40.990: ERROR/AndroidRuntime(679): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
40.990: ERROR/AndroidRuntime(679): at dalvik.system.NativeStart.main(Native Method)
41.000: INFO/Process(576): Sending signal. PID: 679 SIG: 3
41.000: INFO/dalvikvm(679): threadid=7: reacting to signal 3
41.030: ERROR/ActivityThread(576): Failed to find provider info for android.server.checkin
41.030: ERROR/Checkin(576): Error reporting crash: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/crashes
41.070: INFO/dalvikvm(679): Wrote stack trace to '/data/anr/traces.txt'
50.940: WARN/ActivityManager(576): Launch timeout has expired, giving up wake lock!
50.980: WARN/ActivityManager(576): Activity idle timeout for HistoryRecord{4366ac40 {com.android.launcher/com.android.launcher.Launcher}}
sounds to me more like something wrong with your emulator. Why dont you delete your emulator and create a new one and try again with a fresh project.
Hope that will help you. BTW why are you using emulator on 1.5?? Start to build applications for min 2.1.
Good luck.

Categories

Resources