Browse files

fix RCTMultipartDataTask Memory leaks

In the Docs of `NSURLSession` ,


>The session object keeps a strong reference to the delegate until your app exits or explicitly >invalidates the session. If you do not invalidate the session, your app leaks memory until it exits.

The RCTMultipartDataTask will cause memory leaks, it will make `RCTBatchedBridge` and ` RCTMultipartDataTask` will not release.

So call `[session finishTasksAndInvalidate];` at the end of `startTask` function.
Closes #12673

Reviewed By: shergin

Differential Revision: D4896497

Pulled By: javache

fbshipit-source-id: eb5f8761f67ad33a7de081a68a9a7e1d4329bfc0
  • Loading branch information...
ywz2010 authored and facebook-github-bot committed Apr 20, 2017
1 parent 366cb5a commit 47f834a76d76d11bd6f5c2e5856098e5cbc83f83
Showing with 5 additions and 1 deletion.
  1. +5 −1 React/Base/RCTMultipartDataTask.m
@@ -55,6 +55,7 @@ - (void)startTask
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request];
[dataTask resume];
[session finishTasksAndInvalidate];
- (void)URLSession:(__unused NSURLSession *)session
@@ -91,7 +92,9 @@ - (void)URLSession:(__unused NSURLSession *)session
- (void)URLSession:(__unused NSURLSession *)session task:(__unused NSURLSessionTask *)task didCompleteWithError:(NSError *)error
_partHandler(_statusCode, _headers, _data, error, YES);
if (_partHandler) {
_partHandler(_statusCode, _headers, _data, error, YES);
- (void)URLSession:(__unused NSURLSession *)session dataTask:(__unused NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
@@ -111,6 +114,7 @@ - (void)URLSession:(__unused NSURLSession *)session
RCTMultipartStreamReader *reader = [[RCTMultipartStreamReader alloc] initWithInputStream:inputStream boundary:_boundary];
RCTMultipartDataTaskCallback partHandler = _partHandler;
_partHandler = nil;
NSInteger statusCode = _statusCode;
BOOL completed = [reader readAllParts:^(NSDictionary *headers, NSData *content, BOOL done) {

0 comments on commit 47f834a

Please sign in to comment.