【发布时间】:2011-05-11 14:14:13
【问题描述】:
我遇到以下代码泄漏内存的问题...
@property (nonatomic, retain) NSMutableArray *childrensArray;
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"Connection finished loading.");
// Dismiss the network indicator when connection finished loading
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// Parse the responseData of json objects retrieved from the service
SBJSON *parser = [[SBJSON alloc] init];
NSString *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *jsonData = [parser objectWithString:jsonString error:nil];
childrensArray = [jsonData objectForKey:@"Children"];
// Callback to AttendanceReportViewController that the responseData finished loading
[attendanceReportViewController loadChildren];
[connection release];
[responseData release];
[jsonString release];
[parser release];
}
在 viewController 中,以下内容也会泄漏内存...
@property (nonatomic, retain) NSMutableArray *childrensArray;
- (void)loadChildren {
// Retrieve a array with dictionaries of children from ServiceGetChildren
self.childrensArray = [[serviceGetChildren.childrensArray copy] autorelease];
int total = [childrensArray count];
totalLabel.text = [NSString stringWithFormat:@"%d", total];
[theTableView reloadData];
}
【问题讨论】:
-
请您清理一下您发布的代码。
-
我只是说,但是.. 在你的泄密线之后(
childrensArray = [serviceGetChildren.childrensArray copy];你有一个{而不是}。另外,我希望这不是完全复制全部粘贴一次,但部分复制粘贴,对吧?因为如果布局完全一样,还有更多..嗯,事情,错了。 -
@toto 是的,当然很抱歉。现在可能更容易阅读。
标签: iphone objective-c ios memory-leaks