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

iOS: KrollBidge, reference and memory leak

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Invalid
    • Affects Version/s: Release 3.5.0
    • Fix Version/s: None
    • Component/s: iOS
    • Environment:

      Ti SDK 3.5.0 master
      ios sdk 8
      xcode 6.1

      Description

      To make it short it is really easy to create a retain cycle on iOS that will prevent proxies from being deallocated, thus creating huge memory leaks

      Very simple example:

      This won't create a retain cycle

          var win = Ti.UI.createWindow({
              backgroundColor:'red'
          });
          win.addEventListener('click',function() {
              win.close();
          });
          win.open();
      

      This will (example 1)

          var win = Ti.UI.createWindow({
              backgroundColor:'red'
          });
          testMe = function() {
              win.close();
          }
          win.addEventListener('click',testMe);
          win.open();
      

      Same as this (example 2)

          var win = Ti.UI.createWindow({
              backgroundColor:'red'
          });
          win.testMe = function() {
              win.close();
          }
          win.addEventListener('click',win.testMe);
          win.open();
      

      You can simply test it by adding a breakpoint in TiWindowProxy dealloc method.
      You will break in the first example after clicking the window. You won't in the second and third

      The reason is actually pretty simple:

      • example1 : the top context holds a reference to testMe
        testMe's context holds a reference to win.
        Thus win can't be dealloc, then testMe can't be dealloc ....
      • example2:win holds a reference to testMe. testMe's context holds a reference to win. => retain cycle

      Those 2 examples simply a very important retain cycle in the SDK.
      This should be handled to prevent such things.
      I have been wrapping my head around this one but it's not easy to fix

        Attachments

          Activity

            People

            • Assignee:
              ingo Ingo Muschenetz
              Reporter:
              farfromrefuge Martin Guillon (Inactive)
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Source Code