When I zoom in/zoom out from time to time in my map activity I get in console an “OutOfMemory error:bitmap size exceeds VM budget”. The app doesn’t crash on my developement phone, but I’m not sure If this issue won’t cause a problem in future.
Note: I display maximum 30 custom markers on map.
The error stack doesn’t reference my code. Does anyone have a fix or a best practice to get rid of this error?
Thanks in advance.
public void onCreate(Bundle savedInstanceState) {
...
marker = getResources().getDrawable(R.drawable.marker);
...
fillData();
}
public void fillData() {
...
for (int i = 0; i < lats.length; i++) {
...
map.getOverlays().add(new ContactOverlay(marker, tempLat, tempLon, names[i],
phones[i]));
}
}
private class ContactOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> items = new ArrayList<OverlayItem>();
public ContactOverlay(Drawable marker, double latitude,
double longitude, String title, String snippet) {
super(marker);
boundCenterBottom(marker);
items.add(new OverlayItem(getPoint(longitude, latitude), title,
snippet));
populate();
}
@Override
protected OverlayItem createItem(int i) {
return (items.get(i));
}
...
}
Try to reuse the bitmap and the canvas where you draw. Each time when you redraw the overlay, a new bitmap is allocated.