0

I am running a stack of image filters and seem to be hitting some memory issues.

At the beginning of the image processing I am using this much memory:

GC_FOR_MALLOC freed 3K, 45% free 3237K/5831K, external 47586K/49634K, paused 17ms

At the end I am using this much (after all processing is finished):

GC_EXTERNAL_ALLOC freed 5K, 16% free 16056K/18951K, external 51430K/52196K, paused 23ms

After I am finished with each bitmap I set it to recycle and to null:

someBitmap.recycle();
someBitmap = null;

Is there anything else I should be doing to them? Is there any cleanup I should do to the Canvas being used?

Also my filters are objects instantiated like:

BoxBlurFilter blurFilter = new BoxBlurFilter();

Is there anything I should do to release them? In iOS memory allocated with "new" I am responsible to free.

Sorry for the trivial memory management questions, but I am quite new to Android dev and things are quite different than iOS.

Thank you!

EDIT 2, I removed my full filter code.

Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58
  • It's definitely different, this is actually one of the common tricky memory management problems in Android. Can you post a bit more code so that we can see what's going on? There are *some* (pretty rare) instances where calling `System.GC()` is necessary/helpful. – kabuko Jan 21 '12 at 04:41
  • Thanks kabuko. I tried adding System.GC() after each bitmap is set to null and doesn't seem to help. I will try to post some pseudo code or something. – Jeshua Lacock Jan 21 '12 at 04:44

1 Answers1

-1

So after setting the filter instances to null and all the byte arrays to null (in the code above and in the filter objects) I now have approximately the same size heap as I did before I run the filter:

GC_EXPLICIT freed 5126K, 77% free 3243K/13703K, external 51430K/53478K, paused 18ms

That means it went from 16mb being used to 3.2mb. Much better!

So I guess the answer to my question is make sure you set everything to null if you want it to be freed.

Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58