Memory Leak in Map Overlays

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Memory Leak in Map Overlays

Postby gostyloj » Tue Jan 12, 2010 6:10 pm

I have a huge memory leak with my map overlays. I have debugged and tested out my threads to make sure they are closing ad nausium so I am going to start by supposing that the memory leak is with my Map Overlay and work my way from there.

I am loading overlays onto my map and when the map is panned I am removing all the overlays and loading new ones. The data to create the overlays is retrieved in a thread. The application works, it just leaks over a meg of memory every reload.

What is the appropriate way of getting rid of overlays so the garbage collector cleans it up? What am I doing wrong?

This is what I am doing (not the full code).

// getting my overlays list
private List<Overlay> overlays;
overlays = mapView.getOverlays();

// trying to get rid of old overlays
for (Overlay i : overlays)
{
if (i instanceof ParcelOverlay)
((ParcelOverlay) i).cleanUp();
}
overlays.clear();
// and loading new overlays
int count = 0;
while (count < parcelData.length)
{
overlays.add(new ParcelOverlay(MapFrontEnd.this, parcelData[count]));
count++;
}


The actual overlays use the MapActivity as a context. The overlay draws some rectangles, has a text paint where it loads a font and can load up to 3 bitmaps depending on the data.

// font loading:
face = Typeface.createFromAsset(context.getAssets(), "fonts/sd_led_screen.ttf");

//example of image load
buildingBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.playerstore);

//and this is what I have added to attempt to clean up loose ends. this is called before overlays.clear().

public void cleanUp()
{
context = null;

if (buildingBitmap != null)
{
buildingBitmap.recycle();
buildingBitmap = null;
}
if (ghostBitmap != null)
{
ghostBitmap.recycle();
ghostBitmap = null;
}
if (presentBitmap != null)
{
presentBitmap.recycle();
presentBitmap = null;
}
}
gostyloj
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 28, 2009 12:52 pm

Top

Postby gostyloj » Wed Jan 13, 2010 6:54 am

I finally found my issue. For some reason:
face = Typeface.createFromAsset(context.getAssets(), "fonts/sd_led_screen.ttf");
was not letting go of all its resources. I am not sure the exact mechanics but I think it was filling the cache and not releasing that memory.

When I pull out the font into my singleton activity and reference it from my overlays everything seems to work correctly and I don't rapidly run out of memory.
gostyloj
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 28, 2009 12:52 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest