Select to view content in your preferred language

MapView freezes when leaving Activity (SDK v. 10.2)

3769
9
01-23-2014 12:06 AM
MarekJarzynski
New Contributor
After updating the SDK to version 10.2 we encounter a new problem which causes the app to freeze. The problem appears from time to time when the user the leaves the Activity which has a MapView in its layout. When I managed to investigate is that the problem is caused when the MapView object is removed from memory. Normally removing of MapView should look like this (logs from LogCat):
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <start>:GLThread 554
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- release WebMapTask>:GLThread 554
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- shutdown threadpool>
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- pause (release)>
 D/ArcGIS.LifeCycle(10955):    MapSurface released
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- recycle layers>
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- release map>
 D/ArcGIS.LifeCycle(10955):  < MapSurface.Context recycled. com.esri.android.map.MapSurface{418e66b0 V.E..... ........ 0,0-640,671}
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- release done!>
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <done>


But from time to time it suddenly stops during this process, then the log look like that:
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <start>:GLThread 554
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- release WebMapTask>:GLThread 554
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- shutdown threadpool>
 D/ArcGIS.LifeCycle(10955):    MapSurface.destroyContext <- pause (release)>
 D/ArcGIS.LifeCycle(10955):    MapSurface released


Next no further log is printed until the app notifies about the crash.

Has anyone encountered the same problem or found any solution to it ?
0 Kudos
9 Replies
ThomasBinu
Deactivated User
I have been facing the same issue after upgrading to ArcGIS 10.2 SDK. Any updates to solve this?
I am testing on a Galaxy s3 running Android 4.3
0 Kudos
DanO_Neill
Deactivated User
After updating the SDK to version 10.2 we encounter a new problem which causes the app to freeze


Are you saying that an app that worked as expected prior to 10.2 and after updating the app to 10.2 the issue started?  Has the source code for the app not changed only updating to 10.2 libraries?  Can you share any source to reproduce this issue?
0 Kudos
ThomasBinu
Deactivated User
I have been doing some tests with the hello world map sample to replicate this issue. Well..it seems that the map activity seems to leaking small amounts of memory. I am not sure if this leak is related to the ANR issue we are having occasionally when user leaves the activity.You can replicate this issue by adding a plain android  activity before the Esri map activity and opening and closing the map activity couple of times and checking the heap dump. Even after invoking the garbage collector multiple times, we can still see many instances of the map activity in the heap dump. It seems that  some ArcgisTiledserviceLayer object is holding a reference to the activity which prevents it from being garbage collected.

I followed the steps from the video on the link below to analyse the memory leaks.
http://www.youtube.com/watch?v=_CruQY55HOk

My test device was a Galaxy note 8.0 with Android 4.1.2

Could you verify this issue from your end?

I have already tried putting map.recycle/map=null in onDestroy method but it did not work
0 Kudos
MarekJarzynski
New Contributor
Are you saying that an app that worked as expected prior to 10.2 and after updating the app to 10.2 the issue started?  Has the source code for the app not changed only updating to 10.2 libraries?  Can you share any source to reproduce this issue?


Our application looks very similar to an example that tmsbn90 desribed. We've got main activity from which an app user can open new Activity containing MapView. I add three layers to the mapView, OpenStreetMapLayer as the background, ArcGISLocalTiledLayer in the front and Graphic layer for showing graphic markers. When we were using SDK v. 10.1 after entering the activity containing the map it was clearly visible that the application was using much more memory than in the beggining. We conducted tested which clearly shhowed that there are memory leakage problems. Single app used not more than 45-50 MB for RAM, after entering the map activity 10 times app used about 100 MB, it was clearly visible than every time the user entered the activity about 5 MB leaked.

That is why we decided to upgrade the SDK to 10.2 version. The problem with memory leakage disappeared, now the map activity is closed propearly, but from time to time while closing this activity the app crashes.
I tried various ideas to avoid this, what helped a bit was adding this piece of code before leaving the activity:

  if (mMapView != null) {
   if (!mMapView.isRecycled()) {
    Layer[] ll = mMapView.getLayers();
    if (ll.length > 0) {
     for (Layer layer : ll) {
      mMapView.removeLayer(layer);
      layer.recycle();
     }
    }
   }
   mMapView = null;
  }


It removes all layers just before the app would do it. It helped a bit still the problem exists.
0 Kudos
ThomasBinu
Deactivated User
Thank you marcus0202. Although, I am surprised that after your 10.2 upgrade, the memory leak has disappeared. I did many tests today using the 10.1 and 10.2 SDK, and although the memory leak problem is not as bad as the 10.1 SDK, the leak still exists. If youanalyse the heap dump after some tests , you can see multiple instances of the map activity in the memory.
0 Kudos
teamIgal
Deactivated User
After using eclipse memory analayzer, is seems that i have a memory leak as well.

I have noticed that the leak is happening when i add TPK to the map view (if i remove the TPK's then everything is OK).

Also - i have unstoppable calles to GC_Concurrent when i use the TPK.
0 Kudos
DanO_Neill
Deactivated User
We have found the memory leak and it will be fixed in our next release, v10.2.2.  Thanks for everyone's help and patience with this issue.
0 Kudos
ThomasBinu
Deactivated User
We have found the memory leak and it will be fixed in our next release, v10.2.2.  Thanks for everyone's help and patience with this issue.


We have upgraded our application to 10.2.2 and can confirm the crashes and memory leaks have been fixed. Keep up the good work android team.
0 Kudos
ThomasBinu
Deactivated User
We have found the memory leak and it will be fixed in our next release, v10.2.2.  Thanks for everyone's help and patience with this issue.


We have upgraded our application to 10.2.2 and can confirm the crashes and memory leaks have been fixed. Excellent work guys!!.
0 Kudos