开发者

Why is KVO retaining all of NSMutableArray's objects?

开发者 https://www.devze.com 2023-03-14 08:49 出处:网络
I\'m having a real pain trying to figure out why KVO is retaining all values that are being observed.

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 CFArrayCreate开发者_如何学运维Mutable 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?


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.

0

精彩评论

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

关注公众号