我做了一个applciation.In使用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];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
中的viewDidLoad()
.SO请告诉我它的发布地点。
答案 0 :(得分:1)
您应该保存对NSURLConnection
:
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
你应该开始它:
[connection start];
您应该在didFailWithError
或connectionDidFinishLoading
中发布。