开发者

UIActivityIndicatorView nillify makes it crash

For 开发者_高级运维the code below if I nillify the indicator by "self" it crashes if dont use self than no crash. Isnt it the rule that I should always use "self" to access ivars created and retained by @property ?

@property(nonatomic,retain) UIActivityIndicatorView* activityIndicator;


if(activityIndicator!=nil){
     [activityIndicator removeFromSuperview];
      //self.activityIndicator = nil;  //crashes!
              activityIndicator = nil;       //does not crash
 }


Generally speaking:

  self.activityIndicator = nil;  //crashes!

will release the activityIndicator, so this is possibly related to the crash.

 activityIndicator = nil;       //does not crash

will not release the activity indicator, you don't have a crash, you have a memory leak.

In your concrete case, possibly the crash depends on the fact that when you execute this:

 [activityIndicator removeFromSuperview];

the activity indicator is released; now, if it also happens that retain count goes to 0, the object is also deallocated, but the property is not updated to reflect the fact that the object has been deallocated. SO, when you set it to nil, the setter tries to release it, but the obejct dos not exist anymore and hence the crash.

This is a guess. It should not happen if you retained correctly the activity indicator in your class. So, either you review the code where you create the activity indicator and the places in your code where you use activityIndicator or you post it for more help...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜