Why is KVO retaining all of NSMutableArray's objects?

落花浮王杯 提交于 2019-12-11 15:34:42

问题


I'm having a real pain trying to figure out why KVO is retaining all values that are being observed.

Scenario: I have an NSMutableArray with weak references. (Set up with CFArrayCreateMutable and Callback having NULL for both retain and release). Meaning any object added is never retained / released.

I have an NSArrayController observing values of the NSMutableArray.

But now, every object of the NSMutableArray is also retained. Why is this happening and how do I stop this?


回答1:


How do you know that something is retaining these objects? You're not looking at -retainCount, are you? If yes, don't do that.

If you read about the way KVO works, you'll find that there are some objects created behind the scenes when you start observing objects. You really don't need to know or think about those objects in order to use KVO successfully -- indeed, there's not much that you can know -- but you also shouldn't worry about who other than yourself might or might not be retaining things.



来源:https://stackoverflow.com/questions/6400627/why-is-kvo-retaining-all-of-nsmutablearrays-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!