mapbox-plugins-android: Memory leak when using the mapbox-plugins
Hi, I’m using mapbox on my android app and it is working great. But when I try to use the locationPlugin to display the user position, I see the consommation of my memory going up when the user move. Unfortunately, if the user is constantly moving, the app will crash due to a Out of Memory.
The issue may be related to the locationEngine.setInterval()/setFastestInterval() since in the doc of both we have :
If this rate is faster than your app can handle, you may encounter problems with UI flicker or data overflow
Below is a test that I recreate having the same issue :
`
private LocationLayerPlugin locationPlugin;
private LocationEngine locationEngine;
private MapboxMap map;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Mapbox.getInstance(getContext(), MyMapbox.getToken());
binding = DataBindingUtil.inflate(inflater, R.layout.test, container, false);
binding.mapView.onCreate(savedInstanceState);
binding.mapView.getMapAsync(this);
return binding.getRoot();
}
@Override
public void onStart() {
super.onStart();
binding.mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
binding.mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
binding.mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
binding.mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
binding.mapView.onLowMemory();
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (locationEngine != null) {
locationEngine.removeLocationUpdates();
locationEngine.removeLocationEngineListener(this);
locationEngine.deactivate();
}
if (locationPlugin != null) {
locationPlugin.onStop();
}
binding.mapView.onDestroy();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
binding.mapView.onSaveInstanceState(outState);
}
@SuppressLint("MissingPermission")
@Override
public void onConnected() {
locationEngine.requestLocationUpdates();
}
@Override
public void onLocationChanged(Location location) {
Log.d(LOG_TAG, "TEST");
}
private void enableLocationPlugin() {
if (locationPlugin == null) {
LocationEngineProvider locationEngineProvider = new LocationEngineProvider(getContext());
locationEngine = locationEngineProvider.obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.BALANCED_POWER_ACCURACY);
locationEngine.setFastestInterval(1000);
locationEngine.setInterval(1000);
locationEngine.addLocationEngineListener(this);
locationEngine.activate();
locationPlugin = new LocationLayerPlugin(binding.mapView, map, locationEngine);
}
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
map = mapboxMap;
enableLocationPlugin();
}`
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 16 (8 by maintainers)
Thanks everyone involved for code snippets and testing! The issue seems to be resolved with https://github.com/mapbox/mapbox-gl-native/pull/12296 that will be included in the
0.7.0release targeted EOW next week.In the meantime, could you retest your implementations while manually including Maps SDK snapshot dependency?