0

in my app i am trying to show page curl effect using 100 images as explained in the following github link - here

In the sample code they are using only two images but in my app i am using around 90 images. This causes the app to get crashed, saying the following issue in logcat

E/dalvikvm-heap(603): Out of memory on a 5529616-byte allocation.

When i tried with 7 images it was working good. When i try to increase more than 7, it gets crashed. All my images are in drawable folder.

In that github code the images from drawable are taken as follows

mPages.add(BitmapFactory.decodeResource(getResources(),R.drawable.page9));
        mPages.add(BitmapFactory.decodeResource(getResources(),R.drawable.page10));
        mPages.add(BitmapFactory.decodeResource(getResources(),R.drawable.page11));
        mPages.add(BitmapFactory.decodeResource(getResources(),R.drawable.page12));
        mPages.add(BitmapFactory.decodeResource(getResources(),R.drawable.page13));
        mPages.add(BitmapFactory.decodeResource(getResources(),R.drawable.page14));
        mPages.add(BitmapFactory.decodeResource(getResources(),R.drawable.page15));

how to resolve this issue and load all the images, any better suggestions...

Kara
  • 6,115
  • 16
  • 50
  • 57
Siva K
  • 4,968
  • 14
  • 82
  • 161

2 Answers2

0

You must realize that the heap per application is quite limited in Android, so you can't use as much memory as on a desktop PC. So here are the solutions you might want to use:

  1. Use smaller size images.
  2. Optimize your application behavior, means you should not load any Bitmaps that aren't used at a moment and recycle them properly as soon as they become needless.
  3. Limit the number of Bitmaps, which already works for you.

Hope you'll implement one of these to make your application work better.

Egor
  • 39,695
  • 10
  • 113
  • 130
0

Use lazy loading mechanism. Do not load all bitmaps into memory at once, keep there id's in an ArrayList, and load them as you need them, and after using them, unload the bitmap, so that memory can be released.

Kayhan Asghari
  • 2,817
  • 1
  • 28
  • 47