Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
203 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...