我对 iOS 3.0+ 中的内存管理有另一个问题,我知道如果我们这样做 [varialbe release] 会将其保留释放到一个对象,但是这样的代码 -
- (void) getPostsFromJson:(NSData *)data
{
NSError *theError = nil;
NSDictionary *dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:data error:&theError];
if (dict == nil) {
[SystemStatusValues getInstance].isValidJson = NO;
[SystemStatusValues getInstance].httpStatus = HTTP_STATUS_FAILED;
NSLog(@"getPostsFromJson - %@ %@",
[theError localizedDescription],
[[theError userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
} else {
NSArray *keys = [dict allKeys];
keys = [keys sortedArrayUsingFunction:keySortByInteger context:nil];
self.keys = keys;
self.posts = dict;
NSLog(@"Posts : getPostsFromJson = %@", self.posts);
if ([keys count] < TOTAL_SECTIONS) {
[SystemStatusValues getInstance].isValidJson = NO;
} else {
[SystemStatusValues getInstance].isValidJson = YES;
if (self.nextPosts == nil) {
}
}
// [keys release];
// [dict release];
return;
}
}
你可以看到有两个局部变量——keys和dict,我需要在代码末尾调用[keys release]还是[dict release]?实际上我做到了,但它有时会带来粉碎。那么对于局部变量,我们不需要在使用后释放它吗?