开发者

Is it correct to write [self.someproperty release]

开发者 https://www.devze.com 2023-02-24 05:53 出处:网络
When i implement dealloc method i used to write: [preopertyX release]; Tod开发者_开发问答ay i found this code:

When i implement dealloc method i used to write:

[preopertyX release];

Tod开发者_开发问答ay i found this code:

[self.propertyX release];

I'm not sure that this method is completely correct. What do you think about ? (we can take as assumption that propertyX is a retained and synthesized property).


From my understanding, you should either set it to nil or you can release the instance variable.

[self setPropertyX:nil]

or

[propertyX release]

The method you list can have unwanted side effects, but if you want the side actions of your setter to happen, I suggest setting to nil.

The accepted answer here: iPhone - dealloc - Release vs. nil is pretty good.

This is a nice debate outlining, pretty vibrantly, the methods available to you.

http://iphonedevelopment.blogspot.com/2010/09/dealloc.html followed up by http://www.red-sweater.com/blog/1423/dont-coddle-your-code


You can write [self.propertyX release] if you have set propertyX retained and synthesized otherwise not

0

精彩评论

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