0

Somewhere in an ARC project, I have:

//Class1.h
@interface Class1 {
    NSDictionary * dict;
}

@end

//Class1.m
@implementation Class1

-(void)loadDict {
    NSDictionary * dict = [[NSDictionary alloc] init];
    // Now load couple of (NSString *, NSString *) pairs into the dictionary
    ...
}

-(void)releaseAllMemoryUsedByDict {
    //TODO
}

@end

How do I release all the memory occupied by dict, on demand? I guess if I had an NSMutableDictionary, I could call its removeAllObjects method. How would I do it for NSDictionary? Would setting dict = NULL work?

4

2 回答 2

4

假设nil没有其他对象持有(强烈引用)NSDictionary.

于 2012-06-27T11:27:31.840 回答
4

如果您设置NSDictionarytonil或任何对象,它将被释放,假设没有其他对象持有对它的引用(这在 ARC 环境中)。

于 2012-06-27T11:28:36.733 回答