Android Question GMaps crashes under stress test

FrankBerra

Active Member
Licensed User
Longtime User
Hi all
I am experiencing some strange behaviour when using google maps library (https://www.b4x.com/android/forum/threads/google-maps-android-v2-tutorial.24415) during stress tests. I used the code as showed at that link.

Scenario:
In my app when i click a button on Panel1 a second panel (Panel2) pops up displaying some images and another panel containing a the map.
When i click the back button the Panel2 is put in the background and all views are removed from Panel2 and now i am back to Panel1.

Everything works in normal conditions, but on old phones i noticed something strange so i conducted some more tests also on newer phones.

This is what is happening:
1) Clicking the button on Panel1 and then clicking the back button on Panel2 after map is correctly diplayed and all images loaded everything works correctly if this procedure is repeated less than about 10 times. After about 10 times the images are downsampled and after some retry the app creshes saying something like this:
B4X:
1-08 18:18:58.812 12190 13417 W art     : Throwing OutOfMemoryError "Failed to allocate a 4194316 byte allocation with 3944088 free bytes and 3MB until OOM"
01-08 18:18:58.840 12190 13417 I B4A     : ~e:java.lang.OutOfMemoryError: Failed to allocate a 4194316 byte allocation with 3944088 free bytes and 3MB until OOM
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at android.graphics.Bitmap.nativeCreate(Native Method)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at android.graphics.Bitmap.createBitmap(Bitmap.java:831)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at android.graphics.Bitmap.createBitmap(Bitmap.java:775)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.c.i.a(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.c.l.a(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.c.l.a(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.c.l.b(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.c.b.ak.a(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.c.b.as.a(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.x.a(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.l.a(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.l.b(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.cv.f(Unknown Source)
01-08 18:18:58.840 12190 13417 I B4A     : ~e:    at com.google.maps.api.android.lib6.gmm6.m.cv.run(Unknown Source)

2) Clicking QUICKLY button on Panel1 then the back button and again the button on Panel1 it loads everything in Panel2 except the map that remains blank. As soon as i quit the app it crashes with the following error:
B4X:
01-08 18:28:24.667 15900 15900 E AndroidRuntime: FATAL EXCEPTION: main
01-08 18:28:24.667 15900 15900 E AndroidRuntime: Process: test.app, PID: 15900
01-08 18:28:24.667 15900 15900 E AndroidRuntime: java.lang.RuntimeException: Unable to pause activity {test.app/test.app.main}: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x6c
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3381)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3315)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.ActivityThread.-wrap13(ActivityThread.java)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-08 18:28:24.667 15900 15900 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x6c
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.content.res.Resources.getResourceName(Resources.java:2235)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:968)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.FragmentManagerImpl.dispatchPause(FragmentManager.java:1967)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.FragmentController.dispatchPause(FragmentController.java:185)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.Activity.performPause(Activity.java:6361)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1311)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3367)
01-08 18:28:24.667 15900 15900 E AndroidRuntime:     ... 10 more


None of the problems above occours if map is deactivated/removed from my project.

So my questions for the gurus here are:
- regarding the first problem it seems a memory problem, so how can i release resources held by maps when i remove all views (included the panel that holds the map) from Panel2?
- Why in the second case the map stay blank and crashes the app at the exit?

Thanks in advance for the help!
 
Last edited:

FrankBerra

Active Member
Licensed User
Longtime User
Someone had the same problem: http://stackoverflow.com/questions/...android-api-v2-supportmapfragment-memory-leak

And the suggestions reported here
http://stackoverflow.com/questions/31726621/android-maps-v2-memory-leak-locationclienthelper
and here
https://code.google.com/p/gmaps-api...Stars ApiType Internal&groupby=&sort=&id=8446

says:
You can work around the leak for now by explicitly disabling the my-location layer in onDestroy ( #setMyLocationEnabled(false) ).

@Overridepublicvoid onDestroy(){if(mMap !=null){
mMap.setMyLocationEnabled(false);}}

It seems that LocationClientHelper$ListenerTransport is related to setMyLocationEnabled(). I had to unregister some callbacks to prevent memory leak.

How to implement this in B4A?
OR how to use and reuse Google Maps without falling into OutOfMemory Error?
 
Upvote 0
Top