Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-5279

iOS: Repeatedly Scrolling a Table View Leaks Memory




      When you repeatedly scroll up and down in a table view, memory is progressively leaked and is not reclaimed until a memory warning occurs. Do this for long enough, and the app will crash.

      When This Happens

      Based on experimentation, I see an inverse correlation between number of rows in the table and how quickly you need to scroll up and down before the table view will start leaking memory. For example, if you only have 50 rows, you have to scroll very quickly to get the problem to start. But if you increase that to 200 rows, it is much easier to see the leak. Further, with 200 rows, if you slowly scroll through, you won't see the problem.

      Sample Code

      Consider the following code, and download the attached iproducts.png to your resources directory:


      var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
      var rows = [];
      for (var i = 0; i < 200; i++) {
          var row = Ti.UI.createTableViewRow();
          row.add(Ti.UI.createLabel({ text: 'Row ' + i, left: 70 }));
          row.add(Ti.UI.createImageView({ image: 'iproducts.png', left: 10 }));
          row = null;
          data: rows,
          bottom: 50
      var freeMemory = Ti.UI.createLabel({
          height: 50, bottom: 0
      setInterval(function() {
          freeMemory.text = 'Free Memory: ' + Ti.Platform.availableMemory;
      }, 1000);
          modal: true,
          modalStyle: Ti.UI.iPhone.MODAL_PRESENTATION_FORMSHEET

      Steps To Reproduce

      1. Drop the above in an app.js
      2. Download the attached iproducts.png to your Resources directory
      3. Run the app on an iPad 1; I have reproduced this in the simulator, but it is easier to see and reproduce on an actual device
      4. Slowly scroll through the whole table, making sure all of the rows are loaded.
      5. Look at the "Free Memory" label. You probably saw it decrease as the rows were loaded, and then stabilize. Slow scrolling through the table might cause this number to change, but it should stay pretty stable.
      6. Now rapidly scroll up and down in the table view. You should be going at a rate of around 2-3 flicks per second to go from top to bottom, and then 2-3 flicks to get back to the top in another second.
      7. Keep doing step 6, and watch "Free Memory". It might stay stable for a couple of seconds, but then you should see it go down by a megabyte or more per second. The OS will send a memory warning, and you'll jump back up to having lots of free memory. But it will continue to drain memory, and continue to hit memory warnings, until the OS forces the app to terminate.


          Issue Links



              • Assignee:
                stephentramer Stephen Tramer
                dtoth Dawson Toth
              • Watchers:
                0 Start watching this issue


                • Created:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    Sync status:
                    Last received:
                    Last sent:

                    Git Integration