Android Google Maps MapController memory leaks
I am getting severe memory leak when using google maps for android. I notice this especially when using mapController.animateTo. See example code: starting in Amsterdam. I'm heading south towards Italy, increasing my write speed, but within 3 minutes it goes over 20MB, # the object is up to 68000 or more and the app crashes. Does anyone know what could be the cause or workaround?
public class MapsLeakActivity extends MapActivity
{
MapView mapView = null;
MapController mapController = null;
Location mLoc = new Location("");
GeoPoint mGP = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mapsleak);
mapView = (MapView) findViewById(R.id.mapviewml);
mapView.setKeepScreenOn(true);
mapView.setSatellite(false);
mapView.setBuiltInZoomControls(false);
mapController = mapView.getController();
mapController.setZoom(17);
// We start in Amsterdam
mLoc.setLatitude(52.29);
mLoc.setLongitude(5.09);
Timer timer = new Timer();
TimerTask moveOn = new TimerTask()
{
@Override
public void run()
{
// Italy here we come ;) (if it wasn't for the memoryleaking)
mLoc.setLatitude(mLoc.getLatitude() - 0.05);
mLoc.setLongitude(mLoc.getLongitude() + 0.05);
mGP = new GeoPoint((int)(mLoc.getLatitude() * 1E6), (int) (mLoc.getLongitude() * 1E6));
mapController.animateTo(mGP);
// System.gc(); Tried this already; does not help!
}
};
timer.schedule(moveOn , 1000, 2000);
}
@Override
protected void onResume()
{
super.onResume();
}
@Override
protected void onPause()
{
super.onPause();
}
@Override
protected void onDestroy()
{
super.onDestroy();
}
@Override
protected boolean isRouteDisplayed()
{
return (true);
}
}
+3
source to share
No one has answered this question yet
Check out similar questions: