2

I have a map in my application that shows locations from Gowalla. I use an ItemizedOverlay with a simple default marker, but as the items are drawn, I swap the default marker out with the location's icon downloaded 9and cached on disk) from Gowalla.

The problem is that if there are a lot of locations on screen (say 30), the size of the bitmaps in memory is enough to crash the activity. To prevent this, I only keep SoftReferences to the bitmaps. Unfortunately, this means that locations will flicker between the default marker and the icon (i.e., icons are loaded, but then there is memory pressure, so they're removed, but then reloaded because they're on screen...).

When I download the images from Gowalla, I'm already scaling them down based on the screen size (48x48 for HDPI, so 32x32 for MDPI, etc.), so these aren't huge images, but I'm still forced to choose between potentially crashing my app or having the icons flicker in and out. Is there some other way I can reduce the memory that a Bitmap uses?

noah
  • 21,289
  • 17
  • 64
  • 88

2 Answers2

1

This will always be a problem unfortunately. You can try downsampling. Strange out of memory issue while loading an image to a Bitmap object

You might try saving the images to a temporary file system so that you don't have to hit the web every time. That should help a lot or maybe even 100% with the flicker. Couple that with an access-based heap cache (if you feel up to building one), and you're probably good.

Community
  • 1
  • 1
Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
0

The flickering problem is due to the use of Soft References. Android aggressively clears them and they are not recommended in the docs. I would guess they are only in Android for compatibility. I should have been using an LruCache instead.

noah
  • 21,289
  • 17
  • 64
  • 88