小编max*_*eis的帖子

Analyzer标记了此构造的潜在泄漏

使用以下代码,分析器将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)

分析师不抱怨.我错过了什么?

iphone xcode memory-leaks analyzer

0
推荐指数
1
解决办法
2556
查看次数

标签 统计

analyzer ×1

iphone ×1

memory-leaks ×1

xcode ×1