在C ++类中保留ARC对象

我有一些必须保留为c ++的代码,但是我需要将Objective-C对象存储在这些c ++类中.在将对象存储在此处时,将不会在其他任何地方引用这些对象,因此我不能将它们从我身下删除.在ARC之前,我只是保留了它们,然后才将它们放入c ++类,并在删除它们时自动释放它们.一切正常.

I have some code that must remain as c++, but I need to store objective-c objects in these c++ classes. The objects will not be referenced anywhere else while they are stored here, so I can't have them deleted out from under me. Before ARC, I just retained them before putting them into the c++ class, and autoreleased them when they were removed. Everything worked fines.

但是对于ARC,我不确定该怎么办.使c ++变量__unsafe_unretain足够吗?好像不是这样,因为一旦obj-c代码不再使用该对象,它将被删除,或者我不明白__unsafe_unretained的作用.我可以在ARC下调用CFRetain()和CFAutorelase()吗?

But with ARC, I'm not sure what to do. Is making the c++ variables __unsafe_unretained enough? Doesn't seem like it is because once the obj-c code isn't using that objects anymore it will be deleted, or am I not understanding what __unsafe_unretained does. Can I call CFRetain() and CFAutorelase() under ARC?

在ARC下处理此问题的正确方法是什么? NSArray到底在做什么以保持其存储的对象?

What is the right way to deal with this under ARC? What does NSArray do down deep to keep the objects it is storing?



 1 条回答