Many are faced with this problem. You have three ways to solve this problem:
- Increase available memory: stop services or change your device to a newer one.
- Reduce memory usage: by optimizing code
- [UPDATE] Free up unused bitmap memory: call recycle () .
- [UPDATE] Do not use GarbageCollector :)
Usually with Bitmap problems, a garbage collector will help.
Justin Breitfeller's answer links to a more detailed explanation of the internal workings of Bitmap. The message that needs to be removed is that the memory allocated for the bitmap image data (in the createBitmap native method) is processed separately and is not freed directly by GarbageCollector when Bitmap becomes a garbage collector. The real solution is to recycle () your bitmaps when you are not using them. This will still retain the (small) memory allocated for the Bitmap object, but mark the (large) memory allocated for the garbage collector. Consequently, the GarbageCollector in turn frees both, but you do not need to call it manually before OutOfMemory happens, the JVM will try the GarbageCollect anyway.
Andras BalΓ‘zs Lajtha
source share