My app gets killed with OOM but onTrimMemory methods are not called
I use Fresco for image caching, because I have a lot of images on 4.4 devices my app gets killed with OOM. I tried overriding methods like onTrimMemory() from both Activities that display images and Application class where I try to clear cache in order to avoid OOM but my app still crashed. After that I tried setting logs in this methods and I have noticed that even though my app crashes this methods are not called
There isn't much code to show:
override fun onTrimMemory(level: Int) {
Timber.d("GalleryActivity onTrimMemory %s", level)
if (level == ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) {
Fresco.getImagePipeline().clearCaches()
}
}
Am I doing something wrong or isn't my understanding right? Shouldn't these methods be called when the app is taking too much memory ?
Are there any ways to tackle this problem ? Thanks
Update, this is how the log looks like:
at android.graphics.Bitmap.createBitmap(Bitmap.java:913) at android.graphics.drawable.VectorDrawable$VectorDrawableState.createCachedBitmapIfNeeded(VectorDrawable.java:834) at android.graphics.drawable.VectorDrawable.draw(VectorDrawable.java:318) at android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:916) at com.facebook.drawee.drawable.ForwardingDrawable.draw(ForwardingDrawable.java:185) at com.facebook.drawee.drawable.ScaleTypeDrawable.draw(ScaleTypeDrawable.java:123) at com.facebook.drawee.drawable.FadeDrawable.drawDrawableWithAlpha(FadeDrawable.java:302) at com.facebook.drawee.drawable.FadeDrawable.draw(FadeDrawable.java:289) at com.facebook.drawee.drawable.ForwardingDrawable.draw(ForwardingDrawable.java:185) at com.facebook.drawee.generic.RootDrawable.draw(RootDrawable.java:81)