title: Reason for High Memory usage in Android MapView
body: <p>I found the GC kicks in frequently freeing memory in my map activity, I couldn't trace out the reason and this happens when map start constructing titles i.e when we slide the map. And eventually the activity stops to force quit due to memory out of bound exception. The activity points the geo points of various location stored in the arraylist. The image enclose show this. </p>
  
  <pre><code>public class DetailMapTab extends MapActivity{
  private MapView map=null;
  private MyLocationOverlay me=null;
  private SitesOverlay sites=null;
  String placename;
  int position;
  String lat;
  String lon;
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist =new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mapdetail);
  
  
  //position -&gt; is the selected record of the list 
  //mylist -&gt; contains record sets to display like name , lat and lon of various location
  placename=mylist.get(position).get("Name");
  lat=mylist.get(position).get("Latitude");
  lon=mylist.get(position).get("Longitude");
  
  
  
  
  
  map=(MapView)findViewById(R.id.map);
  
  map.getController().setCenter(getPoint(Double.valueOf(lat),Double.valueOf(lon)));
  
  map.getController().setZoom(17);
  map.setBuiltInZoomControls(true);
  
  sites=new SitesOverlay();
  map.getOverlays().add(sites);
  
  me=new MyLocationOverlay(this, map);
  map.getOverlays().add(me);
  
  
  
  
  }//oncreate
  
  @Override
  public void onResume() {
      super.onResume();
  
      me.enableCompass();
  }       
  
  @Override
  public void onPause() {
      super.onPause();
  
      me.disableCompass();
  }       
  
  @Override
  protected boolean isRouteDisplayed() {
      return(false);
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_S) {
          map.setSatellite(!map.isSatellite());
          return(true);
      }
      else if (keyCode == KeyEvent.KEYCODE_Z) {
          map.displayZoomControls(true);
          return(true);
      }
      else if (keyCode == KeyEvent.KEYCODE_H) {
  
          return(true);
      }
  
      return(super.onKeyDown(keyCode, event));
  }
  
  private GeoPoint getPoint(double lat, double lon) {
      return(new GeoPoint((int)(lat*1000000.0),(int)(lon*1000000.0)));
  }
  
  private class SitesOverlay extends ItemizedOverlay&lt;CustomItem&gt; {
  
      private List&lt;CustomItem&gt; items=new ArrayList&lt;CustomItem&gt;();
  
  
      public SitesOverlay() {
          super(null);
  
          //show selected record geo-point with a new map pin1
  
          items.add(new CustomItem(getPoint(Double.valueOf(lat),Double.valueOf(lon))," ", placename,getMarker(R.drawable.pin1)));
  
  
  
            //show the geo-points names with pin2
  
              for(int i=0;i&lt;mylist.size();i++)
              {
  
  
                  if(position!=i)
                  {
  
                  items.add(new CustomItem(getPoint(Double.valueOf(mylist.get(i).get("Latitude")),Double.valueOf(mylist.get(i).get("Longitude"))),"",mylist.get(i).get("Name"),getMarker(R.drawable.pin2)));
                  }
              }
          }
  
      }
      populate();
      }
  
      @Override
      protected  CustomItem createItem(int i) {
          return(items.get(i));
      }
  
      @Override
      public void draw(Canvas canvas, MapView mapView,boolean shadow) {
          super.draw(canvas, mapView, shadow);
  
      }
  
      @Override
      protected boolean onTap(int i) {
          //OverlayItem item=getItem(i);
          Toast.makeText(getApplicationContext(),items.get(i).getSnippet(),Toast.LENGTH_SHORT).show();
          return(true);
      }
  
      @Override
      public int size() {
          return(items.size());
      }
  
  
  
      private Drawable getMarker(int resource) {
          Drawable marker=getResources().getDrawable(resource);
  
          marker.setBounds(0, 0, marker.getIntrinsicWidth(),marker.getIntrinsicHeight());
          boundCenterBottom(marker);  
  
          return(marker);
      }
  }
  
  
  
   class CustomItem extends OverlayItem {
      Drawable marker=null;
  
  
      CustomItem(GeoPoint pt, String name, String snippet, Drawable marker) {
          super(pt, name, snippet);
  
          this.marker=marker;
  
      }
  
      @Override
      public Drawable getMarker(int stateBitset) {
          Drawable result= marker;
  
          setState(result, stateBitset);
  
          return(result);
      }
  
  
  }
  
  
    public void onDestroy(){
           super.onDestroy();
  
  
          map=null;
          me=null;
          sites=null;
  
          gr=null;
          placename=null;
          lat=null;
          lon=null;
          mylist =null;
           System.gc();
  
  
  
       }
   }
  </code></pre>
  
  <p>I am glad to know the reason. The log shown as when I slide the map </p>
  
  <pre><code> 11-11 15:39:55.072: DEBUG/dalvikvm(222): GC freed 439 objects / 83360 bytes in 106ms
   11-11 15:39:56.052: DEBUG/dalvikvm(107): GC freed 3568 objects / 197464 bytes in 138ms
   11-11 15:39:57.451: DEBUG/dalvikvm(222): GC freed 135 objects / 41456 bytes in 101ms
   11-11 15:39:59.891: DEBUG/dalvikvm(222): GC freed 94 objects / 42112 bytes in 134ms
   11-11 15:44:27.481: DEBUG/dalvikvm(104): GC freed 7472 objects / 406240 bytes in 140ms
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/QlB1r.png" alt="alt text"></p>