iphone - 这是释放内存的好方法吗?

标签 iphone objective-c memory-management

我在 iPhone 上编程已经有一段时间了,在内存管理方面有过糟糕的经历。我想知道下面的方法是否是释放内存的好方法。

int count = [someObject retainCount];

for (int i = 0; i < count; i ++) 
{
[someObject release];
}

在我遇到的一些情况下(特别是 UIWebViews),这种方法是一种绝望的行为。变量的 retainCount 减少到零,这将释放它正在使用的内存。该方法有点脏,但是否存在与之相关的瓶颈?

最佳答案

你不应该依赖于 retainCount 因为 iOS 框架有可能保留对象,

阅读下文 AppleretainCount 的评价。

Important: This method is typically of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

要了解您必须遵守的内存管理基本规则,请阅读“Memory Management Rules ”。要诊断内存管理问题,请使用合适的工具:

关于iphone - 这是释放内存的好方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6534594/

相关文章:

ios - map View - 移动 map View 后的当前位置

iphone - 关于流体布局的问题

c++ - 通过引用传递与通过指针传递时对象的范围

iphone - 如何仅在 iOS 5 上执行代码而不破坏应用程序

iphone - 从代码中更改 UIFileSharingEnabled

c - 如何克服输入函数中链表第一个元素的奇数内存分配?

c - 如何在 Linux 上调试内存覆盖

iphone - 如何打印证书的公钥(Objective-C)

iphone - 如何使用 Objective-C 协议(protocol)

iphone - 隐藏导航栏的标题