Fix memory leak in iOS implementation of HTTPClient
@interface URLConnection : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
-(id)init;
+-(void)deinit;
-(NSError*)sendSynchronousRequest:(NSURLRequest*)request didReceiveResponse:(BOOL(^)(NSURLResponse*))responseHandler didReceiveData:(BOOL(^)(NSData*))dataHandler;
@end
return self;
}
+-(void)deinit {
+ [self.session finishTasksAndInvalidate];
+}
+
-(NSError*)sendSynchronousRequest:(NSURLRequest*)request didReceiveResponse:(BOOL(^)(NSURLResponse*))responseHandler didReceiveData:(BOOL(^)(NSData*))dataHandler {
NSURLSessionDataTask* dataTask = [self.session dataTaskWithRequest:request];
@@ -116,9 +121,12 @@ namespace carto {
}
HTTPClient::IOSImpl::~IOSImpl() {
+ @autoreleasepool {
URLConnection* connection = (__bridge_transfer URLConnection*)_connection;
+ [connection deinit];
_connection = nullptr;
}
+ }
void HTTPClient::IOSImpl::setTimeout(int milliseconds) {
_timeout = milliseconds;
