Objective-C - 测试被释放/释放的对象实例 [英] Objective-C - Test for object instance being dealloced/freed
本文介绍了Objective-C - 测试被释放/释放的对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一些方法来测试一个目标c实例被释放/释放(retain count == 0)
There's some way to test for an objective-c instance for being dealloced/freed (retain count == 0)??
例如,对象A有一个引用(指针)到对象B,但是对象B可以在内存低级别释放,我如何测试引用B以确保它被释放??
By example, object A have a reference (pointer) to object B, but object B can be freed in memory low levels, how i test reference B to be sure it was dealloced??
@interface A : NSObject {
B b;
}
@implementation A {
- (void) someAction:(id) sender {
//is b previously dealloced??
if ..... ???? {
b = [[B alloc] init];
}
// continue
}
}
谢谢!
推荐答案
你不能测试一个对象是否已经被释放,再谈。如果你在发布时将 b
设置为nil(例如,通过执行 self.b = nil
你可以测试nil然后创建对象。
You can't test whether an object has been dealloced since, obviously, the object isn't there to talk to anymore. If you set b
to nil when you release it (say, by doing self.b = nil
), though, you can test for nil and create the object then.
这篇关于Objective-C - 测试被释放/释放的对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文