我刚刚在一些工作了几个月的代码中注意到了这一点。虽然这让我好奇的我敢肯定,我们一直生活在借来的时间...死亡后的物体寿命(保留计数= 0)
假设activeItem:
@property (nonatomic, retain) ItemView *activeItem;
而且我们有这个条件在touchesEnded:
if (CGRectContainsPoint(dropRect, touchLocation)) {
ItemView *replacementItem = [[ItemView alloc] initWithFrame:frame];
[newItems replaceObjectAtIndex:[newItems indexOfObject:activeItem] withObject:replacementItem];
[self addSubview:replacementItem];
[controller.view.subView addItem:activeItem];
[replacementItem goCenter];
[replacementItem release];
}
唯一保留activeItem是NSArray,newItems
。我应该在拨打replaceObjectAtIndex
之前保留它,然后在我发布replacementItem
时将其释放?其他方式?
似乎工作正常,但不是EXC_BAD_ACCESS之前的时间问题?!?
想通了......你的帖子让我思考。它仍然被视图保留... – Meltemi 2010-01-22 04:09:11
另外,iPhone上没有弱引用(还没有)(因为没有GC ...) – 2010-01-22 04:22:25
Kendall Helmstetter Gelner:你可以有一个弱点(也就是非保留)没有GC的参考。 '__weak' *关键字*仅适用于GC。 – 2010-01-22 05:14:58