[英]How to release the NSUrlConnection class object,NSMutableData class object?
iam进行一个应用程序。在该iam中,使用NSUrlconnection类。下面是我的代码。
- (void)viewDidLoad {
[super viewDidLoad];
responsedata = [[NSMutableData data] retain];
NSString *url = [NSString stringWithFormat:@"https://www.google.com"];
NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:URL];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
[request release];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responsedata setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responsedata appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
}
在此代码中,当执行iam时,它表示在responsedata = [[NSMutableData data] retain];
内存泄漏responsedata = [[NSMutableData data] retain];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
在viewDidLoad()
SO中,请告诉我它的发布位置。
您应该保存对NSURLConnection
引用:
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
您应该启动它:
[connection start];
并且您应该在didFailWithError
或connectionDidFinishLoading
释放它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.