iOS开发 不能不知的事(1)

_contents = [[NSMutableArrayalloc] init];//[_contentsretainCount] 为 1

self.contents = [[NSMutableArrayalloc] init];//[_contentsretainCount] 为 2

所以self.contents要慎用

 

if (_contents)

{

            [_contents release];

            self.contents = nil;

 }

 

知道这一句为什么为异常吗?

它的展开为:

if (_contents)

{

   [_contents release]; 

  if(_contents)

  {

     [_contents release];//关键是这一句出错

    _contents = nil;

  }    

 }

 

posted @ 2014-03-13 13:07  lao cai  阅读(116)  评论(0)    收藏  举报