【发布时间】:2011-11-08 12:31:27
【问题描述】:
我有一个非常简单的类,叫做 Profile。它包含名为 avatar 的 NSMutableArray,而它又包含 UIImages。这个 NSMutableArray 被声明为 nonatomic,retain 属性。它是在 Profile 的 init 方法中分配的,如下所示:
avatar = [[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],
[UIImage imageNamed:@"image4.png"],
[UIImage imageNamed:@"image5.png"],nil] ;
并在 Profile 的 dealloc 方法中发布。
在我的 AppDelegate 中,我有一个名为 currentProfile 的全局 Profile 对象。它用于各种文件。并且一旦我需要释放该对象的头像数组以便将其与另一个数组一起复制。但是复制永远不会完成,因为我在释放数组时遇到了运行时错误。当我分析代码时,我得到以下信息:
属性返回一个具有 + 0 保留计数(非拥有引用)的objective-с对象
调用者此时不拥有的对象的引用计数减少错误
怎么了?为什么我不能释放数组?仅仅因为它是一个类的成员?如果是这样,我怎样才能用新的替换数组的内容?
【问题讨论】:
标签: objective-c memory-leaks xcode4 release