Does the object returned from cc.loader.getXMLHttpRequest() need to explicitly retained on the Javascript side?
I’m trying to solve some intermittent crashes that look very much like references to hashtables in memory thats been cleaned up already.
@pandamicro - wondering if this PR is relevant? https://github.com/cocos2d/cocos2d-x/pull/12661
Thanks
The answer is yes, if the request is not used straight away.
In other words, this would be bad:
var req = cc.loader.getXMLHttpRequest();
setTimeout(function () {
// req native object may have been garbage collected by cocos2x here
req.onreadystatechange = function () {
if (req.readyState === 4) {
// request complete..
}
};
req.open("GET", 'http://httpbin.org/get?show_env=1', true);
req.send();
}, 0);
Not that you’d ever do this. But, I had introduced an async callback (to get an auth token) and had placed it between creating and using the XMLHttpRequest without realising the implications.