Objective-C Library - cannot form weak reference to instance of class

前端 未结 3 650
借酒劲吻你
借酒劲吻你 2021-02-08 11:38

I\'m currently working with the XMPP Library for Objective-C, and I\'m using the \"Desktop\" example code.

It logs in fine; however, when I open a new chat, or someone s

3条回答
  •  面向向阳花
    2021-02-08 12:09

    Looking at Mike Ash's blog, I found an interesting paragraph:

    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.

    Did you turn ARC on in your app? If you turn it off, do you get better results?

提交回复
热议问题