-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(android): fix memory error in imageAsResized #14233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m1ga The issue you have tagged with this PR seems that it was not return 0
for recycled bitmaps which caused that issue, but some incorrect calculations for sizeOf
. I believe this should fix that error as well because it:
- Considers bitmap memory reuse across decode/encode operations, especially for
BitmapFactory.Options
which is used inimageAsResized
and other similar methods. - Gives the actual memory footprint of a Bitmap in RAM.
- Already returns
0
for recycled bitmaps.
@Override
protected int sizeOf(String key, Bitmap bitmap)
{
// Divide by 1024 to keep both the maxSize and sizeOf in KB.
return bitmap.getAllocationByteCount() / 1024;
}
sadly it doesn't work with that code change. Here is the output with the test code from the issue :
when selecting a 4th image it will start with the error again. |
Did you test it with a fresh installation after deleting the older cache usages? This time it's thrown at the per-image level, not at the application level (
📝Next Steps:
|
yes, fresh installation. I think it still should be good to revert the old #14156 PR with this one so it's back to the initial behaviour (showing the warning but not crashing) as people reported this on slack and have errors in 12.7.0. Then we should search for the deeper issue |
I did a more digging and noticed that the LruCache implementation needs some overhaul. So it's fine to revert for now, but can you please add the handling to catch With the |
I've added a general exception catch so it will catch everything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The apps would keep running now (without cached images in these cases), so the warnings are fine. I will try to find the root-cause and provide a fix on this.
Edit: Also, the current cache related code can also be moved to a background thread and make the actual Blob return faster.
* fix(android): fix memory error in imageAsResized * try/catch
reverts #14156
more info and test code in #14232