mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 21:53:30 +00:00
fix RCTMultipartDataTask Memory leaks
Summary: In the Docs of `NSURLSession` , >IMPORTANT >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 https://github.com/facebook/react-native/pull/12673 Reviewed By: shergin Differential Revision: D4896497 Pulled By: javache fbshipit-source-id: eb5f8761f67ad33a7de081a68a9a7e1d4329bfc0
This commit is contained in:
parent
366cb5a00a
commit
47f834a76d
@ -55,6 +55,7 @@ static BOOL isStreamTaskSupported() {
|
|||||||
}
|
}
|
||||||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request];
|
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request];
|
||||||
[dataTask resume];
|
[dataTask resume];
|
||||||
|
[session finishTasksAndInvalidate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)URLSession:(__unused NSURLSession *)session
|
- (void)URLSession:(__unused NSURLSession *)session
|
||||||
@ -91,7 +92,9 @@ didReceiveResponse:(NSURLResponse *)response
|
|||||||
|
|
||||||
- (void)URLSession:(__unused NSURLSession *)session task:(__unused NSURLSessionTask *)task didCompleteWithError:(NSError *)error
|
- (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
|
- (void)URLSession:(__unused NSURLSession *)session dataTask:(__unused NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
|
||||||
@ -111,6 +114,7 @@ didBecomeInputStream:(NSInputStream *)inputStream
|
|||||||
{
|
{
|
||||||
RCTMultipartStreamReader *reader = [[RCTMultipartStreamReader alloc] initWithInputStream:inputStream boundary:_boundary];
|
RCTMultipartStreamReader *reader = [[RCTMultipartStreamReader alloc] initWithInputStream:inputStream boundary:_boundary];
|
||||||
RCTMultipartDataTaskCallback partHandler = _partHandler;
|
RCTMultipartDataTaskCallback partHandler = _partHandler;
|
||||||
|
_partHandler = nil;
|
||||||
NSInteger statusCode = _statusCode;
|
NSInteger statusCode = _statusCode;
|
||||||
|
|
||||||
BOOL completed = [reader readAllParts:^(NSDictionary *headers, NSData *content, BOOL done) {
|
BOOL completed = [reader readAllParts:^(NSDictionary *headers, NSData *content, BOOL done) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user