aaronksaunders / TiParseTestApp

Other
18 stars 7 forks source link

Memory leak w/HTTPClient #4

Open adampash opened 10 years ago

adampash commented 10 years ago

I've been using this to work with Parse in Titanium, and on doing some profiling in iOS discovered that the network proxy is never released. Cursory testing showed setting xhr to null released the object, but I'm having trouble getting down the appropriate timing for that. Any thoughts/suggestions?

Fwiw, this fix appears to be working for me at the moment:

    xhr.onreadystatechange = function() {
      if (handled) return;
      if (4 === xhr.readyState) {
        handled = !0;
        if (xhr.status >= 200 && 300 > xhr.status) {
          var response;
          try {
            response = JSON.parse(xhr.responseText);
          } catch (e) {
            promise.reject(e);
          }
          var fauXhr = {
            status: xhr.status
          };
          response && promise.resolve(response, fauXhr.status, fauXhr);
          xhr = null;
        } else {
          var fauXhr = {
            status: xhr.status
          };
          promise.reject(fauXhr);
          xhr = null;
        }
      }
    };