How to release the NSUrlConnection class object,NSMutableData class object?
iam making one applciation.In that iam using the NSUrlconnection class.Below one is my code.
- (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];
}
In this code when iam executing,it shows the memory leak at
responsedata = [[NSMutableData data] retain];开发者_StackOverflow中文版
[[NSURLConnection alloc] initWithRequest:request delegate:self]; in viewDidLoad()
.SO please tell me where it released.
You should save reference to your
NSURLConnection:NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];You should start it:
[connection start];And you should release it in
didFailWithErrororconnectionDidFinishLoading.
加载中,请稍侯......
精彩评论