Skip to content

Commit

Permalink
Merge pull request #8883 from bn-dignitas/8843-fix-request-memory-ret…
Browse files Browse the repository at this point in the history
…ention

#8843 Clean up request data references
  • Loading branch information
lilleyse authored Jun 3, 2020
2 parents f1aac14 + bac46c9 commit 71c5250
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Jakub Vrana](https://github.com/vrana)
- [Edvinas Pranka](https://github.com/epranka)
- [James Bromwell](https://github.com/thw0rted)
- [Brandon Nguyen](https://github.com/bn-dignitas)
9 changes: 8 additions & 1 deletion Source/Core/RequestScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ function getRequestReceivedFunction(request) {
requestCompletedEvent.raiseEvent();
request.state = RequestState.RECEIVED;
request.deferred.resolve(results);
// explicitly set to undefined to ensure GC of request response data. See #8843
request.deferred = undefined;
};
}

Expand Down Expand Up @@ -218,7 +220,12 @@ function cancelRequest(request) {
var active = request.state === RequestState.ACTIVE;
request.state = RequestState.CANCELLED;
++statistics.numberOfCancelledRequests;
request.deferred.reject();
// check that deferred has not been cleared since cancelRequest can be called
// on a finished request, e.g. by clearForSpecs during tests
if (defined(request.deferred)) {
request.deferred.reject();
request.deferred = undefined;
}

if (active) {
--statistics.numberOfActiveRequests;
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1367,9 +1367,12 @@ Resource.prototype._makeRequest = function (options) {

return promise
.then(function (data) {
// explicitly set to undefined to ensure GC of request response data. See #8843
request.cancelFunction = undefined;
return data;
})
.otherwise(function (e) {
request.cancelFunction = undefined;
if (request.state !== RequestState.FAILED) {
return when.reject(e);
}
Expand Down

0 comments on commit 71c5250

Please sign in to comment.