Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

ScrollView memory hog

We are trying to implement image grid using scroll view (using one image view and one standard view per picture). Data is being fetched from the server.

When the number of pictures is larger than 50, entire GUI becomes unresponsive (debugging shows that it froze in the main loop while adding the images into the view).

Is this a problem with too much views being created for the ScrollView ? This used to work with older titanium versions like 1.3.2 and older.

I've tried eliminating one of the two views being created per picture. Didn't help although the code would freeze at higher picture index being added.

This might be similar to this issue:
http://developer.appcelerator.com/question/46061/serious-memory-leak

Any ideas or workarounds ?

Code snippet:

var scrollView = Ti.UI.createScrollView({
    contentWidth:'auto',
    contentHeight:'auto',
    showVerticalScrollIndicator:true,
    showHorizontalScrollIndicator:false,
    top:30,
    width:320,
    height:340
}); 

var imageOffset = 4;
var topOffset = imageOffset;
var imageDimension = 75;
var nRowSize = 4; 

for (var i=0;i<files.length;i++) 
{
 var filename = files.item(i).getElementsByTagName('FILENAME').item(0).text;
 var thumb = files.item(i).getElementsByTagName('THUMB_BINARY').item(0).text;
 var thumb_binary = Titanium.Utils.base64decode(thumb);

 imageView = Ti.UI.createImageView({
                image:thumb_binary,
                fileName:filename,
                isFolder:false,
                height:75,
                width:75,
                top:topOffset,
                left:leftOffset,
                pictureIndex:i
            });

 leftOffset = imageOffset + (imageOffset+imageDimension) * ((i + nFolderCount) % nRowSize);
 topOffset = imageOffset + (imageOffset+imageDimension) * Math.floor((i + nFolderCount) / nRowSize);

 view = Ti.UI.createView({
                borderColor:'gray',
                borderWidth:1.0,
                fileName:filename,
                isFolder:false,
                pictureIndex:index
            });

 view.add(imageView);
 scrollView.add(view);
}
— asked July 30th 2010 by Marko Perutovic
  • scrollview
0 Comments

1 Answer

  • Accepted Answer

    Possibly relate to this, mine is built on iPad, pretty of juice to handle the scrollview but hang on adding new views dynamically. Can you try assign views in an array then add later after the loop? It helps in my case, though still hang when i loop a few more times.

    There's another user having the same issue too.

    http://developer.appcelerator.com/question/47211/info–dynamic-scrollview-add-views-on-14

    — answered July 30th 2010 by Daniel Lim
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.