2013-04-08 35 views
0

我的方法是不能釋放該變量IOS

-(void)readAppFile 
{ 
    NSString *plistPath = [self getDataFileDestinationPath]; 
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath]; 
    NSString *errorDesc = nil; 
    NSPropertyListFormat format; 
    NSMutableDictionary *temp = (NSMutableDictionary *) [NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc]; 
    if (!temp) { 
     NSLog(@"Error reading plist: %@, format: %d", errorDesc, format); 
    } 
    items = [[temp objectForKey:@"Items"] mutableCopy]; 
    NSLog(@"temp %lu", (unsigned long)[temp retainCount]); 
    [temp release]; 
} 

當我加入了[temp release]; - 但事情是錯誤的,我的方法是崩潰。不明白是什麼錯誤..正如我從內存泄漏儀器可以看到的 - 我需要釋放這個變量..任何幫助?

+0

您可以發佈您收到的錯誤消息嗎?或者可能是一個崩潰日誌? – JDx 2013-04-08 13:49:29

+1

請仔細閱讀本文:[何時使用-retaincount?](http://whentouseretaincount.com) – 2013-04-08 14:02:05

+0

@DavidRönnqvist很好的鏈接,謝謝! – ShurupuS 2013-04-08 14:34:55

回答

0

這retured的自動釋放編號您類型強制轉換成的NSMutableDictionary。

NSMutableDictionary *temp = (NSMutableDictionary *) [NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc]; 

然後鬆開手再次通過[temp release];

1

看你的代碼,你應該釋放items而不是釋放temp