Search code examples
androidscreenshot

Screen capture causing heap to grow


I am trying to take screenshot using the code below:

final View rootView = getRootView();
rootView.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(rootView.getDrawingCache());
rootView.setDrawingCacheEnabled(false);

Once captured, I am storing the screenshot in an ArrayList<Bitmap>.

mReporter.addBitmap(bmp);

The problem is, every time this whole process is performed heap grows by a large amount. How can I avoid the heap growing too large?

My log is showing this info which might be helpful:

05-08 20:11:48.443: I/dalvikvm-heap(18497): Grow heap (frag case) to 31.288MB for 6819856-byte allocation

Edit:

Am storing a max of 3 images in ArrayList


Solution

  • you can not. Everytime you store a new bitmap inside your ArrayList. You can either downsampling your bitmaps or you can keep only few bitmaps in your ArrayList