Use these static methods to find out the exact problem (s):
public static void showBitmapSize(Bitmap bitmap) { Log.d("test", "bitmap dimensions: w:" + bitmap.getWidth() + ", h:" + bitmap.getHeight() + " memory: " + (bitmap.getRowBytes() * bitmap.getHeight() / 1048576d)); }
And the most important thing:
static double lastavail; static double initavail; static boolean first = true; public static void showMemoryStats() { showMemoryStats(""); } public static void showMemoryStats(String message) { Log.i("memory", message + "----------------------------------------------------------------------------------------"); double nativeUsage = Debug.getNativeHeapAllocatedSize(); Log.i("memory", "nativeUsage: " + (nativeUsage / 1048576d)); //current heap size double heapSize = Runtime.getRuntime().totalMemory(); // Log.i("memory", "heapSize: " + (heapSize / 1048576d)); //amount available in heap double heapRemaining = Runtime.getRuntime().freeMemory(); // Log.i("memory", "heapRemaining: " + (heapRemaining / 1048576d)); double memoryAvailable = Runtime.getRuntime().maxMemory() - (heapSize - heapRemaining) - nativeUsage; Log.i("memory", "memoryAvailable: " + (memoryAvailable / 1048576d)); if (first) { initavail = memoryAvailable; first = false; } if (lastavail > 0) { Log.i("memory", "consumed since last: " + ((lastavail - memoryAvailable) / 1048576d)); } Log.i("memory", "consumed total: " + ((initavail - memoryAvailable) / 1048576d)); lastavail = memoryAvailable; Log.i("memory", "-----------------------------------------------------------------------------------------------"); }
Dividing by 1048576 is only getting values ββin MB (at least for me it is easier to think in MB).
Place a call to showMemoryStats with some meaningful message before calling setContentView() , and the other after it. And when you start a new activity, etc. In the end, you will find the exact causes of your problem.
Manual recirculation may be required. I had to implement it in some places of my application. In addition, using an intensive raster image (many backgrounds and pictures), such problems arose on all devices. Using these methods, I was able to find all the problems and deal with them.
Oh. And there is a possible quick fix for your problem, you say that it appears only in Galaxy Nexus. This is the only xhdpi device you mentioned. You probably have all the bitmaps in the drawable or drawable-hdpi folder only. The xhdpi device will accept bitmaps from drawable or drawable-hdpi and scale (although they may already be in the correct size), and this will consume a lot of memory. Decision. Create a drawable-xhdpi folder if it does not exist and place copies of the bitmap images there.
source share