Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17868] Windows: Investigate necessity of protect() and unprotect() usage

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2015-01-07T22:48:35.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.1.0
ComponentsWindows
Labelsmerge-3.4.2
ReporterIngo Muschenetz
AssigneeIngo Muschenetz
Created2014-10-15T17:52:57.000+0000
Updated2015-06-23T19:51:14.000+0000

Description

protect() and unprotect() should be unnecessary for the developer to call directly, but there seem to be some cases where they appear to be required. We need to understand the reasons they are used, and upgrade the infrastructure to remove that necessity. You need to ensure that Ti.UI.createAlertDialog API is exposed, so please copy and paste this into the TiUIModule.cpp js string:
"	 Object.defineProperties(self.TiUIAlertDialog.prototype, {"
"		 'buttonNames': {set:function(value){for(var i=0,len=value.length;i<len;i++) this.addButton(value[i]); this._buttonNames=value;},get:function(){return this._buttonNames;},enumerable: true}"
"	});"
"	exports.createAlertDialog = function(args) {"
"		var a = new self.TiUIAlertDialog();"
"		a.applyProperties(args);"
"		return a;"
"	};"
You also need to remove the protect/unprotect() calls inside AlertDialog. Here's the test, and steps to reproduce: (code under steps) 1. Click on the button 2. See the alert dialog 3. Click on any of the two buttons in less than one second since shown At this point you will see something is the console log 4. Repeat set number 3 but this time wait over a second At this point the log will not show.
var win = Ti.UI.createWindow();
var btn = Ti.UI.createButton({
    title: 'here'
});
win.add(btn);
btn.addEventListener('click', function () {
    var a = Ti.UI.createAlertDialog({title: 'title',message: 'message',buttonNames: ['ok', 'cancel']});
    a.addEventListener('click', function () {
        Ti.API.info('Alert clicked!!!');
    });
    a.show();
    setTimeout(function () {
        Ti.GC();
        Ti.API.info('Garbage collection called');
    }, 1000);
});
win.open();
Explanation: Since the protect and unprotect have been removed, the alert dialog proxy will die when garbage collection is called. In the button event listener we're calling GC (for testing purposes only) after one second. If you click on the button before GC, you're saved and the event listener of the alert is called. If you wait for the GC to be called, the event listener is not called. The share_ptr is likely hiding a bug. In the "click" event handler of the alert's button (native event handler), we're checking if the proxy is still alive or not, and if it's not, we just ignore the callback to avoid a crash. But we need to realize that the native alert object and its buttons may still alive. And the question is, when will the native alert and its buttons be release from memory? This is the reason for a protect and unprotect in the alert dialog proxy. I added the protect and unprotect back to test, and everything will go back to normal.

Comments

  1. Matt Langston 2015-01-07

    This ticket is invalid because HAL assumes responsibility for all JavaScriptCore memory management via RAII.
  2. Eric Merriman 2015-06-23

    Closing as invalid. If you feel this is inaccurate, please reopen.

JSON Source