【发布时间】:2011-10-11 05:52:27
【问题描述】:
我是 iPhone 应用程序开发的新手,当我对我的代码运行泄漏分析器 (XCode->Product->Analyze) 时,我无法纠正此错误。它向我展示了某条线上的对象可能泄漏。
1) 方法返回一个具有 +1 保留计数的目标 c 对象(由于引用)
2) 在第 128 行分配的对象稍后在此执行路径中未引用,并且保留计数为 +1(对象泄漏)。responeData 保留在属性声明部分中
-(IBAction)registerButtonPressed:(id)sender
{
self.responseData = [NSMutableData data];
NSString *username = txtUsername.text;
NSString *jsonstring = [NSString stringWithFormat:@"http://demo.elgghub.com/apis/services/api/rest/json/?method=register&username=%@",username];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:jsonstring]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (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 {
[connection release];
self.responseData = nil;
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Please check your network connection and relaunch the application"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseStringReg = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
NSDictionary *login =(NSDictionary*)[responseStringReg JSONValue] ;
[responseStringReg release];
NSNumber *status = [login objectForKey:@"status"];
NSString *statusString = [status stringValue];
NSString *message = [login objectForKey:@"message"];
}
-(void)dealloc
{
[responseData release];
[demoView release];
[super dealloc];
}
【问题讨论】:
-
第 128 行是哪种方法?
标签: iphone memory memory-leaks