[TIMOB-26961] Windows: Save HttpClient instance until callback is fired
GitHub Issue | n/a |
---|---|
Type | Story |
Priority | None |
Status | Closed |
Resolution | Done |
Resolution Date | 2019-04-08T04:04:24.000+0000 |
Affected Version/s | Release 8.0.0 |
Fix Version/s | Release 8.1.0 |
Components | Windows |
Labels | n/a |
Reporter | Kota Iguchi |
Assignee | Kota Iguchi |
Created | 2019-04-02T02:17:12.000+0000 |
Updated | 2019-04-08T04:04:24.000+0000 |
Description
Currently HttpClient may be garbege-collected before its callback is fired under some circumstances if you don't save HttpClient instance from garbage collector. In that case application crashes. We might want to save HttpClient instance from garbage collection by protecting its instance until
onerror
or onload
callback is called.
var win = Ti.UI.createWindow({
backgroundColor: 'green'
});
win.addEventListener('open', function () {
var _tmpURL = "https://docs.appcelerator.com/platform/latest/#!/api/"
var _tmpClient = Ti.Network.createHTTPClient({
onload: function (e) {
alert('Loaded');
},
onerror: function (e) {
alert("Error:" + e.error);
},
timeout: 30000
});
_tmpClient.open("GET", _tmpURL);
_tmpClient.send();
// In this case _tmpClient may be garbage-collected as soon as this function is finished.
// We could think this as "logical" failure but I think Titanium developers tend to use HttpClient like this.
});
win.open();
No comments