Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out of memory exception with android google maps v2

When i adding and deleting markers on the map, after some time the app crashes with message out of memory exception.

the logcat response is:

02-21 06:04:27.670: E/AndroidRuntime(1892): FATAL EXCEPTION: vts_com.rapidBizApps.mapamine
02-21 06:04:27.670: E/AndroidRuntime(1892): java.lang.OutOfMemoryError
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.bb.d.a(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.s.ap.a(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.ak.r.a(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.ak.e.a(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.ak.e.a(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.ak.o.handleMessage(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at android.os.Looper.loop(Looper.java:130)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.ak.e.j_(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.ak.ad.j_(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.bb.l.b(Unknown Source)
02-21 06:04:27.670: E/AndroidRuntime(1892):     at maps.bb.l.run(Unknown Source)
02-21 06:04:33.260: D/dalvikvm(1892): GC_EXPLICIT freed 2148K, 53% free 5309K/11207K, external 21007K/21768K, paused 71ms

my code is:

loop 20 times:


    mapView.addMarker(new MarkerOptions()
                                        .position(new LatLng(latitude, longitude))
                                        .icon(BitmapDescriptorFactory
                                                .fromBitmap((bitmap)))
                                        .snippet(text + "             ")
                                        .title(mine_name));

For every new loop,i am removing markers on map and adding new ones.

I also took enough care about bitmap as

bitmap.recycle and assign bitmap with null after use of bitmap/

like image 600
Kumar Kalluri Avatar asked Feb 22 '13 05:02

Kumar Kalluri


2 Answers

I have same issue in Google map v2, In my case, my map is refresh at every 30 Seconds. After half an hour my app is crash, I solved this issue using mMap.clear(); where mMapis my object of GoogleMap.

You can put this code before calling of for loop.

hope this will help you.

like image 39
Hiren Patel Avatar answered Nov 16 '22 23:11

Hiren Patel


There is some issue on this google api. We have to wait the next release.... The BitmapDescriptorFactory have memory leak.

http://code.google.com/p/gmaps-api-issues/issues/detail?id=4766&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal

Fixed 25 Jan 13 but not released. Hurry up google!

like image 167
Guillaume Alouege Avatar answered Nov 16 '22 23:11

Guillaume Alouege