使用以下代码,分析器将setMyDict选择器调用标记为潜在泄漏,并且在dealloc中指出"调用者此时不拥有引用计数的不正确减少"
- (id)init {
if (self = [super init]) {
[self setMyDict:[[NSMutableDictionary alloc] init]];
}
return self;
}
- (void)dealloc {
[[self myDict] release];
[super dealloc];
}
@synthesize myDict = _myDict;
Run Code Online (Sandbox Code Playgroud)
我不明白.我想,使用alloc init,对象会将保留计数增加1,指针会通过合成属性存储在_myDict中.如果我使用此代码
- (id)init {
if (self = [super init]) {
_myDict = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)dealloc {
[_myDict release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
分析师不抱怨.我错过了什么?