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

Android: Timers (setTimeout, setInterval) leak memory.

    Details

      Description

      Timers on Android currently never release the callback function
      once the timer has finished (fired once or was cancelled). A leak will
      be created since the callback function and any objects it retains will never get collected.

      Timer leak example

      function startTimer() {
        // 1 mb buffer
        var buffer = Ti.createBuffer({length: 1024 * 1024});
       
        setTimeout(function() {
          alert('Buffer: length = ' + buffer.length);
        }, 2000);
      }
       
      var win = Ti.UI.createWindow();
       
      var startTimerButton = Ti.UI.createButton({title: 'Start timer'});
      startTimerButton.addEventListener('click', startTimer);
      win.add(startTimerButton);
       
      win.open();
      

      1. Run the test code and monitor the heap usage with DDMS.
      2. Click the "Start timer" button and wait for an alert.
      3. Dismiss the alert once it is shown and check the heap usage in DDMS.
      4. Repeat steps 2-3 and watch for heap growth.

      Expected: No long term growth in heap size should happen. It should reach a equilibrium.
      Actual: The heap grows indefinitely eventually running out of memory.

        Attachments

          Activity

            People

            • Assignee:
              joshroesslein Josh Roesslein
              Reporter:
              joshroesslein Josh Roesslein
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Source Code