问题
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