[TIMOB-2313] Android: bitmaps fetched by resource id more susceptible to out-of-memory errors
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:58:44.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 |
Components | Android |
Labels | android, defect |
Reporter | Bill Dawson |
Assignee | Bill Dawson |
Created | 2011-04-15T03:16:27.000+0000 |
Updated | 2011-04-17T01:58:44.000+0000 |
Description
Our internal code that loads bitmaps using resource ids does not have the protection afforded by using certain BitmapFactory.Options which we use when loading the bitmaps by url (instead of resource id). This was an oversight.
Failcase:
Put the attached PNG into Resources/android/images/medium, then run this app.js:
/*global Ti, Titanium, alert, JSON */
Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({
title:'Test',
backgroundColor:'#fff',
fullscreen: true,
exitOnClose: true
});
win.open();
var tv = Ti.UI.createTableView();
var i = 0;
win.add(tv);
var images = [];
for (i = 0; i < 25; i++) {
images.push('images/test.png');
}
for (i = 0 ; i < 50; i++) {
var tr = Ti.UI.createTableViewRow();
tr.add(
Ti.UI.createImageView({images: images})
);
tv.appendRow(tr);
}
The app should crash and if you look at the logcat you should see similar to:
E/AndroidRuntime( 450): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime( 450): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime( 450): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:447)
E/AndroidRuntime( 450): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
E/AndroidRuntime( 450): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
E/AndroidRuntime( 450): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
E/AndroidRuntime( 450): at org.appcelerator.titanium.util.TiUIHelper.getResourceBitmap(TiUIHelper.java:543)
E/AndroidRuntime( 450): at ti.modules.titanium.ui.widget.TiUIImageView.createBitmap(TiUIImageView.java:137)
E/AndroidRuntime( 450): at ti.modules.titanium.ui.widget.TiUIImageView$Loader.run(TiUIImageView.java:268)
E/AndroidRuntime( 450): at java.lang.Thread.run(Thread.java:1096)