1

最近,我声明了一个函数,并将函数放入for如下循环中:

 Bitmap image = ...//Do stuff to get image's bitmap, it's quite ok
 for(int i =0; i < someNumber; i++){
      image = doSomeThing(image, width, height);      
 }

 private Bitmap doSomeThing(image, width, height){
      int[] a = new int[10000];
      Bitmap bitmap = image.copy(sentBitmap.getConfig(), true);
      // Do some stuff here to process image
      ...
      return (bitmap);
 }

for循环参数someNumber小于 5,我的应用程序很好,否则,我将是outOfMemory. 所以我想寻求解决这个问题的建议exception!我可以使用System.gc()吗?或者我可以在每个循环之后做些什么来删除未使用的内存for吗?

编辑:对不起,也许我省略了太多,我更新了我的代码!

Edited2 :如果我多次调用而不是for循环,那就没有了!!image = doSomething(...)exception

谢谢!

4

2 回答 2

1

You probably need to call image.recycle() when you're done with it in the for loop.

Edit: Ah, I see what you're trying to do, apply multiple filters to the same image. Try this:

 Bitmap image = ...;
 for(int i =0; i < someNumber; i++){
      Bitmap newImage = doSomeThing(image, width, height);
      image.recycle();
      image = newImage;
 }
于 2012-08-27T16:00:33.060 回答
0

On a Java standpoint the System.gc() will probably have no effect because as you run out of memory Java will clear it if it can.

Your doSomeThing() call is probably creating too many object for the amount of memory you have.

Either increase it and if you can't because of constraints on memory footprint, adjust your Eden space.

于 2012-08-27T15:56:02.863 回答