Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; public class Main { private static final int OUT_OF_MEMORY_RETRY_COUNT = 5; public static Bitmap createBitmap(int width, int height, Config config) { for (int i = 0; i < OUT_OF_MEMORY_RETRY_COUNT; ++i) { try { return Bitmap.createBitmap(width, height, config); } catch (OutOfMemoryError e) { // Retry with GC. System.gc(); } } return Bitmap.createBitmap(width, height, config); } public static Bitmap createBitmap(Bitmap src) { for (int i = 0; i < OUT_OF_MEMORY_RETRY_COUNT; ++i) { try { return Bitmap.createBitmap(src); } catch (OutOfMemoryError e) { // Retry with GC. System.gc(); } } return Bitmap.createBitmap(src); } }