2012-03-15 93 views
0

我在我的項目中使用了Json框架。內存管理 - 目標C

我解析JSON響應如下,

- (void)parseResponse:(NSData*)responseData 
{ 
    NSMutableString *responseString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
    NSDictionary *responseDic = [responseString JSONValue]; 
    NSString *responseDataString = [responseDic objectForKey:NSLocalizedString(@"JSON_RESPONSE_DICTIONARY_KEY", nil)]; 

    [responseString release]; 
} 

那麼,是不是正確的,如果我呼籲responseString釋放,因爲我做了?

編輯

我沒有如下,

NSMutableString *responseString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

NSDictionary *responseDic = [responseString JSONValue]; 
NSString *responseDataString = [responseDic objectForKey:NSLocalizedString(@"JSON_RESPONSE_DICTIONARY_KEY", nil)]; 
NSDictionary *responseDataDic = [responseDataString JSONValue]; 
[responseString release]; 

我想現在我很安全。

+2

不僅正確,但必要 – MByD 2012-03-15 10:55:03

+1

此外,該陳述的順序是不正確的... – Ilanchezhian 2012-03-15 11:03:06

+0

哦是的是的。我修好了它。感謝很多Aadhira – chinthakad 2012-03-15 11:26:09

回答

1

是,

,如果您使用名稱以「黃金」, 「新」,「複製」,或「mutableCopy」對象的方法。你必須釋放那些對象。

+0

是的。我的問題是它是否會影響** responseDic **實例。所以我編輯了我的方法。 (我通過添加它來編輯我的問題。) – chinthakad 2012-03-15 11:35:24

+2

responseDic是autorelease對象。 [responseString release];不會影響responseDic。 – 2012-03-15 12:11:49