- Application type : Android/iOS
- Titanium SDK : 3.5.1GA
- Platform & version : Android SDK 14 and higher
- Device : I am testing on galaxy tab 7" (real device not emulator)
- Host Operating System: Windows 8.1
- Titanium Studio : 3.4.1
Hi everybody,
I have some trouble with OutOfMemoryError when i am loading some image and/or manipulate/transform this one. A sample of what i do of manipulating
this.filesData[i].siv = Ti.UI.createView({index: i, left: vmp.resized(20), width: vmp.resized(90), height: vmp.resized(90)}); this.filesData[i].siv.addEventListener('postlayout', this.createMiniImage); createMiniImage: function(e) { e.source.removeEventListener('postlayout', vmp.ui.FilesScrollableView.createMiniImage); vmp.modules.initModule('image'); var img = vmp.resizeImage(vmp.ui.FilesScrollableView.filesData[e.source.index].filepath, vmp.resized(90), vmp.resized(90)); if (img) img = img.imageAsCropped({width: vmp.resized(90), height: vmp.resized(90)}); var imagev = vmp.modules.image.getRoundedAvatar(img, parseInt(vmp.resized(90))); img = null; e.source.add(Ti.UI.createImageView({image: imagev, index: e.source.index})); imagev = null; } vmp.resizeImage = function(name, height, width){ var imag = Ti.UI.createImageView({ image: (name.indexOf('/') == -1 ? vmp.ui.t.imgURL(name) : name) }).toBlob(); if (!imag){ Ti.API.info('TEST : '+name); return null; } if(isAndroid) { var h = vmp.resized(imag.height); var w = vmp.resized(imag.width); var ratioOriginal = w/h; if (height && width) { height = parseInt(height); width = parseInt(width); if (width/height > w/h) { w = width; h = w * ratioOriginal; } else { h = height; w = h * ratioOriginal; } } else if (height) { h = height; w = h * ratioOriginal; } else if (width) { w = width; h = w * ratioOriginal; } imag = imag.imageAsResized(w, h); } return imag; }The siv view is add to a scrollView and there is in my app something like 0 to 10 image max in that scrollView. The image before first resize get an average resolution something like 1920*1500. The goal of code above is to get a 'little' circle image of an image. For 3 manipulation pass by the createMiniImage my memory pass of 20MB to 40MB (and apparently that was the limit allocated for my device test).
So my question, there is something wrong on my code (like not correctly release image after manipulate)? Its look like the garbage didn't work efficiently, there is a way to call it at a specific moment (like at the end of the createMiniImage function)? There is something that i can made for tell that my application need more than the 40MB allocate by the device for application? Something else?
All help/council would be appreciate.