Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1090] Memory Usage on ImageViews

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:55:10.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.4.0
ComponentsiOS
Labelsios, iphone, memory, usage, views
Reporterctredway
AssigneeReggie Seagraves
Created2011-04-15T02:43:48.000+0000
Updated2011-04-17T01:55:10.000+0000

Description

A customer has created a slide show type of application and on a device is reporting that after view 4-5 images, the app will become unresponsive and crash.

View this ticket for reference:
http://helpdesk.appcelerator.net/tickets/2782">http://helpdesk.appcelerator.net/tickets/2782

Comments

  1. ctredway 2011-04-15

    from the customer:

    It also looks like TiUIImageView is never being deleted - they just persist in memory - I put a log into TiUIImageView::dealloc, and this is never called, despite removing the item from the window that it was added to and unsetting all references to it.

    Looks like there is a problem.

    -(void)dealloc { NSLog ( @"TiUIImageView::dealloc %@", [NSDate date] );
    if (timer!=nil)
    { [timer invalidate]; } (timer); (images); (container); (previous); (urlRequest); [super dealloc]; }

  2. Jeff Haynie 2011-04-15

    (from [1177e7b3e90095d2ea40e818e26d178f14149e78]) [#1090 state:resolved] fixed major memory leak issue on iphone http://github.com/appcelerator/titanium_mobile/commit/1177e7b3e90095d2ea40e818e26d178f14149e78"> http://github.com/appcelerator/titanium_mobile/commit/1177e7b3e9009...

  3. David R. 2011-04-15

    I'm still experiencing memory leaks with 1.3.3. After 4-5 ImageViews loading JPEG of about 800K the app crashes (no memory). I tried setting the ImageView.image to null, ImageView to null.

  4. David R. 2011-04-15

    While reminding myself :-) that Apple states "You should avoid creating UIImage objects there are greater than 1024x1024 in size." (http://bit.ly/ahftC2)">http://bit.ly/ahftC2), I've run some tests and I was able to reproduce the crash.

    It happens when loading many ImageView instances (each with its own image) into the application. The memory quickly goes down until the app crashes. Best practice shall be then to use fewer ImageView (and smaller images), I believe.

    Thanks Jeff for the good work you're doing here.

    This is the test the makes the app crash (you need one/some images in your Resources folder)

       var win = Ti.UI.currentWindow;
       var memoryLabel = Ti.UI.createLabel({
         text:Ti.Platform.availableMemory,
         top:-20,
         left:0,
         font:{fontSize:22},
         zIndex:-1
       });
       var availMemoryLabel = Ti.UI.createLabel({
         text:Ti.Platform.availableMemory,
         top:20,
         left:0,
         font:{fontSize:22},
         zIndex:-1
       });
       var testStatusLabel = Ti.UI.createLabel({
         text:'status',
         top:-100,
         left:0,
         font:{fontSize:22},
         zIndex:-1
       });


    var imageCounter=1; var imageView=[]; imageView[0] = Ti.UI.createImageView({ width:'auto', height:'auto' });


    var loaded = function() { if ((imageCounter++)>=67) return; testStatusLabel.text=imageCounter+'/67'; imageView[imageCounter-1] = Ti.UI.createImageView({

       width:'auto',
       height:'auto'
       
       
       
       
    }); win.add(imageView[imageCounter-1]); imageView[imageCounter-1].addEventListener('load',loaded); imageView[imageCounter-1].image='images/'+imageCounter+'.jpg';
    }; imageView[0].addEventListener('load',loaded);
    win.add(imageView[0]); win.add(memoryLabel); win.add(availMemoryLabel); win.add(testStatusLabel);
    win.addEventListener('open',function(){ memoryLabel.text=Ti.Platform.availableMemory; setInterval(function(){availMemoryLabel.text=Ti.Platform.availableMemory;},1000) imageView[0].image='images/'+imageCounter+'.jpg'; });

JSON Source