即使释放,引用也不返回 nil
我在这里遇到了一个真正困难的问题。
我的类是自行创建的(+ (void) start;
-方法),该方法被发送给委托。 我需要通过委托选择器向委托发送一些消息。为了检查委托是否被释放,我尝试了 if (delegate == nil/NULL)
,但即使它真的被释放了,它仍然说没有。
我该如何解决这个问题? (委托被分配给一个id
)
这就是我的应用程序的构建方式:
AppDelegate
> NavController
>> TableView
>>> Post
>>>> GetData
GetData 是自创建的类。 Post是GetData的委托,由TableView/NavController释放。释放Post后,也被设置为nil。
换句话说,GetData 不会释放它的委托!
I have run into a real hard one here.
My class is self-created (a + (void) start;
-method) which is sent a delegate.
I need to send the delegate a few messages through delegate-selectors. To check if the delegate was released, I have tried if (delegate == nil/NULL)
, but even if it really is released, it still says it wasn't.
How do I go around to fix this? (delegate is assigned to an id
)
This is how my app is built up:
AppDelegate
> NavController
>> TableView
>>> Post
>>>> GetData
GetData is the self-created class. Post is the delegate of GetData, and is released by TableView/NavController. After releasing Post, it is also set to nil.
In other words, GetData does not release it's delegate!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
释放指针的内容不会自动将指针设置为NULL。您需要明确地执行此操作,例如
Deallocating the content of a pointer does not set the pointer to NULL automatically. You need to do it explicitly, e.g.
您无法检查对象是否已释放。另一个对象可能会出现并占据相同的内存空间,从而与原始对象无法区分。
具有委托的类的用户负责在释放委托对象时将委托设置为
nil
。它不能被物体本身检测到。You can't check if an object was released. Another object could've come along and occupied the same memory space, becoming indistinguishable with the original object.
The user of a class with a delegate is responsible for setting the delegate to
nil
when the delegate object is released. It's not detectable by the object itself.