gpt4 book ai didi

Objective-C 库 - 不能形成对类实例的弱引用

转载 作者:太空狗 更新时间:2023-10-30 03:25:17 34 4
gpt4 key购买 nike

我目前正在使用面向 Objective-C 的 XMPP 库,并且我正在使用“桌面”示例代码。

登录正常;但是,当我打开一个新聊天室或有人向我发送消息时,它会崩溃。

这似乎是哪里出了问题:

XMPPStream[11678:1b03] RECV: 
2012-06-05 15:03:59:379 XMPPStream[11678:1b03] RECV:
2012-06-05 15:03:59:382 XMPPStream[11678:403] RosterController: xmppRosterDidChange:
2012-06-05 15:03:59:387 XMPPStream[11678:403] RosterController: xmppRosterDidChange:
2012-06-05 15:04:01:900 XMPPStream[11678:403] tableView:shouldEditTableColumn:"jid" row:0
2012-06-05 15:04:01:900 XMPPStream[11678:403] user:
objc[11678]: cannot form weak reference to instance (0x7fcd4a498930) of class ChatController

objc[11998]: cannot form weak reference to instance (0x7f853bd17c70) of class ChatController
(lldb)
(lldb)

“无法形成对实例的弱引用……类 ChatController”是什么意思?你们知道我该如何解决吗?我在 Snow Leopard 上使用了此代码的旧版本并且它有效,Lion 把我搞砸了!

谢谢!

最佳答案

查看Mike Ash's blog ,我发现了一个有趣的段落:

ARC's implementation of zeroing weak references requires close coordination between the Objective-C reference counting system and the zeroing weak reference system. This means that any class which overrides retain and release can't be the target of a zeroing weak reference. While this is uncommon, some Cocoa classes, like NSWindow, suffer from this limitation. Fortunately, if you hit one of these cases, you will know it immediately, as your program will crash with a message like this:

objc[2478]: cannot form weak reference to instance (0x10360f000) of class NSWindow

If you really must make a weak reference to classes such as these, you can use the __unsafe_unretained qualifier in place of __weak.

您是否在您的应用中开启了 ARC?如果关闭它,是否会获得更好的结果?

关于Objective-C 库 - 不能形成对类实例的弱引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10904990/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com