以下代码每4秒触发一次请求。
aUrl = [NSURL URLWithString:printUrl];
request = [NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
//MAKE REQUEST
[request setHTTPMethod:@"POST"];
postString = [NSString stringWithFormat:@"h=%@&app=%@v%@&ios=true", hash,iosVersion,version];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
_connectionFetch = [NSURLConnection connectionWithRequest:request delegate:self];
我正在使用ARC而且我对obj c很新。当你经常调用nsurlconnection时,你可以很容易地看到内存增加:
for (int i = 0; i<=10; i++) {
_connectionFetch = [NSURLConnection connectionWithRequest:request delegate:self];
}
在委托中didFailWithError,didReceiveData,didReceiveResponse,connectionDidFinishLoading我用
释放变量_connectionFetch = nil;
我也在清除缓存并禁用它:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
现在的问题是,经过一段时间后,触发URL获取的逻辑停止工作。可能是因为分配了太多内存。内存周期性增加: