Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18096] iOS: Proxies not being released

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2014-12-02T18:43:22.000+0000
Affected Version/sRelease 3.5.0, Release 4.0.0
Fix Version/sRelease 3.5.0, Release 4.0.0
ComponentsCore, iOS
Labelsn/a
ReporterJon Alter
AssigneeVishal Duggal
Created2014-11-25T20:38:30.000+0000
Updated2015-01-08T02:07:36.000+0000

Description

Titanium proxies are not being released. Proxies are released correctly using 3.4.1.GA

Steps to reproduce:

1. Run the code below 2. Run instruments on the xcode project generated 3. Look at allocations 4. Filter by "proxy" 5. Click the buttons in the example app. 6. Notice that the proxies are never released
var win = Ti.UI.createWindow({
    backgroundColor: "white",
    layout: 'vertical'
});
win.open();
 
addButton({
    title: 'create objects',
    callback: function(e) {
        var view = Ti.UI.createView();
        var httpClient = Titanium.Network.createHTTPClient();
        var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'app.js');
    }
});

addButton({
    title: 'open window',
    callback: function(e) {
        openWindow();
    }
});
 
function addButton(args) {
    var b1 = Ti.UI.createButton({
        title: args.title,
        top: 40
    });
    b1.addEventListener('click', args.callback);
    win.add(b1);
}

function openWindow() {
    var win2 = Ti.UI.createWindow({
        backgroundColor: 'blue'
    });
    var v = Ti.UI.createView({
        backgroundColor: 'red',
        height: 50, width: 50
    });
    win2.add(v);
    win2.addEventListener('click', function() {
        win2.close();
    });
    win2.open();
}

Comments

  1. Jon Alter 2014-11-25

    3.4.1.GA

    Event Type ∆ RefCt RefCt Timestamp Responsible Library Responsible Caller

    Malloc/Retain/Autorelease/Release (7) 08:43.458.260 Test -[TiModule createProxy:forName:context:] 1 Retain +1 2 08:43.458.287 Test -[KrollObject initWithTarget:context:] 2 Retain +1 3 08:43.458.323 Test -[KrollBridge registerProxy:krollObject:] 3 Autorelease 08:43.458.422 Test -[KrollMethod call:] 4 Release -1 2 08:43.458.449 Test KrollCallAsFunction 5 Release -1 1 09:04.565.618 Test -[KrollBridge unregisterProxy:] 6 Release -1 0 09:04.565.619 Test -[KrollObject dealloc] 7 Free 0 09:04.565.632 Test -[TiProxy dealloc]

    master

    Event Type ∆ RefCt RefCt Timestamp Responsible Library Responsible Caller

    0 Malloc +1 1 00:04.624.994 Titanium -[TiModule createProxy:forName:context:] 1 Retain +1 2 00:04.625.020 Titanium -[KrollObject initWithTarget:context:] 2 Retain +1 3 00:04.625.046 Titanium -[KrollBridge registerProxy:krollObject:] 3 Autorelease 00:04.625.137 Titanium -[KrollMethod call:] 4 Release -1 2 00:04.625.157 Titanium KrollCallAsFunction It looks like ~KrollFinalizer~ doesn't get called in master
  2. Vishal Duggal 2014-11-26

    Looks like the behavior of the Garbage Collector has changed. KrollFinalizer does get called but there has to be real memory pressure. I modified the sample as shown below and was successfully able to get the GC to kick in and collect objects periodically.
       var win = Ti.UI.createWindow({
           backgroundColor: "white",
           layout: 'vertical'
       });
       win.open();
         
       addButton({
           title: 'create objects',
           callback: function(e) {
               var view = Ti.UI.createView();
               var httpClient = Titanium.Network.createHTTPClient();
               var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'app.js');
           }
       });
        
       addButton({
           title: 'open window',
           callback: function(e) {
               openWindow();
           }
       });
         
       function addButton(args) {
           var b1 = Ti.UI.createButton({
               title: args.title,
               top: 40
           });
           b1.addEventListener('click', args.callback);
           win.add(b1);
       }
        
       function openWindow() {
           var win2 = Ti.UI.createWindow({
               backgroundColor: 'blue',
               layout:'horizontal'
           });
           for (var i=0;i<500;i++) {
               var v = Ti.UI.createView({
                   backgroundColor: 'red',
                   height: 50, width: 50,
                   top:5, left:5
               });
       
               var l = Ti.UI.createLabel({text: i})
               v.add(l);
               win2.add(v);
           }
           win2.addEventListener('click', function() {
               win2.close();
           });
           win2.open();
       }
       
    Going to resolve this as Invalid
  3. Vishal Duggal 2014-12-02

    Pull pending https://github.com/appcelerator/tijscore/pull/18
  4. Ingo Muschenetz 2014-12-09

    Note, this evidently is a problem with using the built-in JavaScriptCore.
  5. Ewan Harris 2015-01-08

    Verified fix on: Mac OSX 10.10.1 Appcelerator Studio, build: 3.4.1.201410281743 Titanium SDK build: 3.5.0.v20150106102524 Titanium CLI, build: 3.4.1 Alloy: 1.5.1 Xcode 6.1.1 iPhone 6 Plus (8.1) Ran the attached code and filtered for proxies in Instrument->Allocations, the proxies are being released as expected. Closing ticket.

JSON Source