This question already has answers here:
Understanding reference counting with Cocoa and Objective-C
                                
                                    (14个回答)
                                
                        
                                6年前关闭。
            
                    
我有一种方法,并且不使用ARC:

-(void)readAppPlist
{
    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: %@, formatL %d", errorDesc, format);
    }
    items = [[temp objectForKey:@"Items"] mutableCopy];
}


根据内存管理规则,我需要在哪里释放变量plistPath,plistXML,errorDesc,temp的内存?我应该编写另一个方法,在此处释放它们还是将它们放入此类的dealloc全局方法中?

最佳答案

假设您正确遵循命名约定(这可能是一个很大的飞跃),答案将是:

plistPath:否
plistXML:否
errorDesc:否
温度:否

规则是,如果您alloc copyretain,则必须释放它(new计为alloc

关于ios - 在没有ARC的iOS中,我需要在哪里释放内存? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15739052/

10-12 15:06
查看更多