为什么KVO保留了NSMutableArray的所有对象? [英] Why is KVO retaining all of NSMutableArray's objects?

查看:157
本文介绍了为什么KVO保留了NSMutableArray的所有对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很想知道为什么KVO保留了所有观察到的值.

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

场景:我有一个NSMutableArray带有弱引用. (使用CFArrayCreateMutable和Callback进行设置,保留和释放都为NULL).意味着添加的任何对象都不会保留/释放.

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.

我有一个NSArrayController,它观察NSMutableArray的值.

I have an NSArrayController observing values of the NSMutableArray.

但是现在,NSMutableArray的每个对象也都保留了.为什么会发生这种情况,我该如何阻止呢?

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

推荐答案

您怎么知道某些东西正在保留这些对象?您不是在查看-retainCount,是吗?如果是,请不要这样做.

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

如果您了解 KVO的工作方式,您会发现在幕后创建了一些对象当您开始观察对象时.您真的不需要了解或思考那些对象就可以成功使用KVO-确实,您 知道的并不多-但是您也不必担心除了自己可能保留或可能不保留东西.

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.

这篇关于为什么KVO保留了NSMutableArray的所有对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆