1

I'm creating Android app which has storing photo funcionality. I noticed that it works slowly, hence I decided to create cache which I store the smallest photo (viewed in gridView) in. I created class:

 public class PhotoCache {
     public static Map<String, Bitmap> photos = new HashMap<String, Bitmap>();
     public static long size = 0;
 }

Then If I want to load bitmap in my app, firstly I check if it is not present in photos variable. If it is then I take it from there. Otherwise I load bitmap from memory and add to photos varialble. The problem which I anylizing now is the size of cache. Every time when I'm adding bitmap to photos variable I'm also adding its size to long variable:

 PhotoCache.size += newBitmap.getByteCount();

Then I print the value of size to observe its growing. It shocked me that after loaded a couple of bitmpas its size is about: 26527680 bytes and there's not any outOfMemory error raised. It is very strange for me why Android allows me to have that big number of bytes in memory. Now I want to secure my app and I have to know the limit of memory which I can store in photos. PS. I know that there is some solutions in Android to cache bitmaps, but I want to use my own.

Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
pumbosha
  • 171
  • 1
  • 9

0 Answers0