0

我已经在目标 C ARC 项目中编写了代码,一切正常,但是在运行我的项目 20-25 后,我的项目崩溃了。我已经在 xcode 仪器上测试了我的项目,我发现我的仪器没有泄漏我观察到我的实时字节在不断增加。有什么方法可以处理这个问题,或者有什么方法可以删除所有内容并释放我项目的分配内存。

4

1 回答 1

3

The most common cause of this is retain cycles. Retain cycles happen when you have two objects A and B that hold strong references to each other. By definition, an object won't get released by ARC until its reference count is 0. Therefore, you can't delete A unless you delete B first, and you can't delete B until you delete A.
To solve this, change one of the strong references to a weak one. Typically, you want the container class to hold a strong reference, and the child class to only hold a weak reference to its container. Here are some examples and more detailed information:

  • Retain Cycle in ARC
  • Advanced Memory Management Programming Guide (Look at the "Use Weak References to Avoid Retain Cycles" section)
  • 于 2013-08-23T19:16:31.377 回答