[TIMOB-27695] Android: Heavy image processing methods do not trigger GC
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Reopened |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | Release 9.0.1 |
Components | Android |
Labels | n/a |
Reporter | Gary Mathews |
Assignee | Gary Mathews |
Created | 2019-12-21T01:39:24.000+0000 |
Updated | 2021-07-20T22:24:46.000+0000 |
Description
- Heavy image processing methods such as
imageAsResized
do not trigger garbage collection and may leave unwanted large blob references that cause OutOfMemory
exceptions.
*TEST CASE*
const win = Ti.UI.createWindow({ backgroundColor: 'gray' });
const img = Ti.UI.createImageView();
win.addEventListener('open', async () => {
// Obtain large image blob. (8205px, 11750px)
let blob = await getImage('https://tinyurl.com/rxob7ju');
// Keep re-sizing the image down by 10%
for (let i = 0; i < 10; i++) {
// De-reference original blob so it can be freed.
blob = blob.imageAsResized(blob.width / 1.1, blob.height / 1.1);
// Idle for 100ms, allowing V8 GC to collect.
// QE: Should not need to do this to display image.
// await new Promise(resolve => setTimeout(resolve, 100));
}
// Display re-sized image.
img.image = blob;
});
win.add(img);
win.open();
function getImage(url) {
return new Promise((resolve, reject) => {
const client = Ti.Network.createHTTPClient({
onload(e) {
resolve(e.source.responseData);
},
onerror: reject,
timeout : 10000
});
client.open('GET', url);
client.send();
});
}
- Application should display resized image without crashing
Attachments
File | Date | Size |
---|---|---|
TIMOB-27695_log_android 7.1.1.txt | 2020-06-24T11:07:52.000+0000 | 32989 |
master: https://github.com/appcelerator/titanium_mobile/pull/11412
*FR: Pass* *Test Environment* SDK Ver: 9.0.0.GA & 9.1.0(this PR) OS Ver: 10.14.6 Appc NPM: 5.0.0 Appc CLI: 8.0.0 Ti CLI Ver: 5.2.2 Node Ver: 10.17.0 Java Ver: 1.8.0_162 Devices: ⇨ Google Pixel 3a (Android 10)
merged to master, cherry-picked to 9_0_X for 9.0.1
*Closing ticket.* Fix verified in SDK version 9.1.0.v20200406120646. and 9.0.1.v20200408050151 (Note image took a long time to load, although it could be due to internet connection as the image is 22mb). Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/11412
It works fine on android 10 and android 9. I am getting below error on android versions < 9.0 {color:#d04437}zygote: Throwing OutOfMemoryError "Failed to allocate a 33554448 byte allocation with 25165824 free bytes and 28MB until OOM, max allowed footprint 96254928, growth limit 100663296" [WARN] W/System.err: java.lang.OutOfMemoryError: Failed to allocate a 33554448 byte allocation with 25165824 free bytes and 28MB until OOM, max allowed footprint 96254928, growth limit 100663296{color} Reopening the ticket. Log attached for the reference of environment details (TIMOB-27695_log_android 7.1.1.txt)