【发布时间】:2011-06-24 02:03:17
【问题描述】:
我正在解析来自 Internet 的一些 JSON,然后将它们添加到一个数组中,该数组是我的 UITableView 的数据源。我不确定什么时候应该释放我的数组?
.h:项目
@property(nonatomic,retain)NSMutableArray* items;
.m:connectionDidFinishLoading
// fetch succeeded
NSString* json_string = [[NSString alloc] initWithData:retrievedData encoding:NSUTF8StringEncoding];
//Check ST status
int status = [[[[json_string objectFromJSONString] valueForKey:@"response"] valueForKey:@"status"]intValue];
//NSLog(@"Status: %d", status);
items = [[NSMutableArray alloc] init];
NSDictionary* messages = [[NSDictionary alloc] init];
switch (status) {
case 200:
messages = [[[json_string objectFromJSONString] valueForKey:@"messages"] valueForKey:@"message"];
for (NSDictionary *message in messages)
{
[items addObject:message];
}
[self.tableView reloadData];
break;
default:
break;
}
【问题讨论】:
-
"我应该什么时候释放我的 X?" - 尽早! ;)
-
你能发布更完整的代码吗?正如所写,这不起作用(或编译)
-
更新了更完整的代码
标签: iphone objective-c cocoa-touch memory nsarray