Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26961] Windows: Save HttpClient instance until callback is fired

GitHub Issuen/a
TypeStory
PriorityNone
StatusClosed
ResolutionDone
Resolution Date2019-04-08T04:04:24.000+0000
Affected Version/sRelease 8.0.0
Fix Version/sRelease 8.1.0
ComponentsWindows
Labelsn/a
ReporterKota Iguchi
AssigneeKota Iguchi
Created2019-04-02T02:17:12.000+0000
Updated2019-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();

Comments

No comments

JSON Source