Bitmap oom

来源:互联网 发布:简明python教程豆瓣 编辑:程序博客网 时间:2024/05/21 06:24



down vote

I had the similar problem while displaying high resolution images. I have searched and applied all the android bitmap solutions given in http://developer.android.com/training/displaying-bitmaps/index.html and the following caches mekanism in the link. but none of them work. not any right solution anywhere. Then I figured out that the problem is : I couldnt use the drawable folder structure right. I was keeping high resolution images in mdpi and hdpi folders . this cause android scale up the images to the ultra sizes. 100 kb image was causing 20 mb increase in memory thanks to the android monitor / memory section. so I have added these ultra resolution images to xxhdpi folder , then It was FIXED suddenly. then my image slider work flawlessly


堆栈等待

waitForGarbageCollector(new Runnable() {  @Override  public void run() {    // Your operations.  }});/** * Measure used memory and give garbage collector time to free up some * space. * * @param callback Callback operations to be done when memory is free. */public static void waitForGarbageCollector(final Runnable callback) {  Runtime runtime;  long maxMemory;  long usedMemory;  double availableMemoryPercentage = 1.0;  final double MIN_AVAILABLE_MEMORY_PERCENTAGE = 0.1;  final int DELAY_TIME = 5 * 1000;  runtime =    Runtime.getRuntime();  maxMemory =    runtime.maxMemory();  usedMemory =    runtime.totalMemory() -    runtime.freeMemory();  availableMemoryPercentage =    1 -    (double) usedMemory /    maxMemory;  if (availableMemoryPercentage < MIN_AVAILABLE_MEMORY_PERCENTAGE) {    try {      Thread.sleep(DELAY_TIME);    } catch (InterruptedException e) {      e.printStackTrace();    }    waitForGarbageCollector(      callback);  } else {    // Памяти достаточно, выполняем операции:    callback.run();  }}

原创粉丝点击