下面的代码上传了一些 JSON 数据,但像疯了一样泄漏内存,我不知道为什么。我将 AFNetworking 2.0 和 ARC 与 XCode 5.0.1 一起使用。根据 Instruments 的说法,有许多 AFRequestOperations 存在,比我预期的要多。但是ARC不应该自动释放它们吗?
NSData *binData = [NSData dataWithBytes:s_print_buff length:(cur_output - s_print_buff) ];
NSURL *url = [NSURL URLWithString:@"http://SOMEIP:SOMEPORT/upload"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"content-type"];
[request setValue:[NSString stringWithFormat:@"%d", [binData length]] forHTTPHeaderField:@"content-length"];
[request setHTTPBody:binData];
AFHTTPRequestOperation *op= [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[[NSOperationQueue mainQueue] addOperation:op];