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
[TIMOB-25540] Android: Fix sizeOf() calculation to prevent IllegalStateException #9620
Conversation
Generated by 🚫 dangerJS |
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.
There is a problem here.
The value passed to the LruCache()
constructor is in kilobytes and the value returned by the sizeOf()
method is in bytes. The two need to use the same units of measure or else the LruCache
won't function correctly. In this case, it'll remove bitmaps from the cache too soon.
From looking at Google's Bitmap
class docs, this method should be written like the below. I also noticed that we were not rounding-up to the nearest kilobyte, which might have been the source of the error?
int byteCount;
if (android.os.Build.VERSION.SDK_INT >= 19) {
byteCount = bitmap.getAllocationByteCount();
} else {
byteCount = bitmap.getByteCount();
}
return (int)Math.ceil((double)byteCount / 1024.0);
Alternatively, switching from kilobytes to bytes for the max size and sizeOf() might be simpler.
Side Note: |
@jquick-axway The crash still occurs with your requested changes. I'm not sure why.. |
I see now, both int byteCount = bitmap.getRowBytes() * bitmap.getHeight();
return byteCount / 1024; |
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.
CR: Pass
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.
FR Passed application no longer crashed when going back and the log showed the following:
resized image
Test steps
- Created a new Titanium project
- Added the test case from the description above
- Built the app using the artefacts from this PR
- Ran the program
- Clicked on a downloaded image
- Console log message was shown as application went to appc logo
- Pressed back
- Application did not crash and was able to view downloaded images
Test Environment
APPC Studio: 5.0.0.201711280737
APPC CLI: 7.0.0
Device: Nexus 6p (8.1.0)
Operating System Name: Mac OS High Sierra
Operating System Version: 10.13
Node.js Version: 8.9.1
onTrimMemory()
can cause an exception when attempting to release memorysizeOf()
calculation to preventIllegalStateException
TEST CASE
JIRA Ticket