开发者

about release object when using kvo in cocoa framework

there are 2 object: A and B

call [A addObserver:B for keyPath:...];

if i release object A in somewhere. have to Call [A removeObserver:开发者_如何转开发B...] first?

if i release object B in somewhere. have to Call [A removeObserver:B...] first?


You only need to do the second one to avoid A sending a message to a deallocated object.


As a matter of good practive, you should remove your observer when it is not needed anymore but not doing so will not cause any problems as neither objects are retained by the message so if you release A it will stop observing B and if you release B the observed value will never change so your KVO observing method will never be called.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜