必须在dealloc中释放非指针实例变量吗?

gon*_*nco 0 iphone sdk class objective-c dealloc

我是否必须releasedealloc类的方法中调用非指针变量?

例如

@interface myClass : NSObject {

    BOOL isDirty; // do i have to release this?
    NSInteger hoursSinceStart; // and this?

    NSDate *myDate; // i will release the pointer in dealloc
}

@property (assign, nonatomic) NSInteger hoursSinceStart; // property to release?

@property (assign, nonatomic) BOOL isDirty; // property to release?
@end
Run Code Online (Sandbox Code Playgroud)

Chu*_*uck 5

两件事情:

  1. 您只需要保留和释放对象.BOOL和NSIntegers不是对象,它们是原始的.

  2. 你通常不应该调用release任何assign属性,因为你没有保留它 - 当然assign是唯一对NSIntegers或BOOL这样的原语有意义的类型,因为你不能保留它们.