我在仪器中测试应用程序,因此代码会导致内存泄漏。请告诉我如何解决它。
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:configuration];
答案 0 :(得分:1)
我不知道我是否迟到了,但回答那些碰到这个问题的人。这是预期的行为。完成会话后,您需要调用此invalidateSessionCancelingTasks:
。
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
self.manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
__weak typeof(self) welf = self;
[self.manager uploadTaskWithRequest:request fromFile:filePath progress:^(NSProgress * _Nonnull uploadProgress) {
// progress block
} completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//Invalidate Session here
[welf.manager invalidateSessionCancelingTasks:YES];
// stuff needed to be done
}];
答案 1 :(得分:0)
您可以尝试以下代码:
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfiguration.HTTPMaximumConnectionsPerHost = 10;
self.manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:sessionConfiguration];
});