开发者

Must non-pointer instance variables be released in dealloc?

Do I have to call release in the dealloc method of a class for non-pointer variables?

e.g.

@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) N开发者_JAVA百科SInteger hoursSinceStart; // property to release?

@property (assign, nonatomic) BOOL isDirty; // property to release?
@end


Two things:

  1. You only need to retain and release objects. BOOLs and NSIntegers are not objects, they're primitives.

  2. You generally shouldn't call release for any assign property, because you haven't retained it — and of course assign is the only type that makes sense for primitives like NSIntegers or BOOLs, since you can't retain them in the first place.


You don't need to release your BOOL or NSInteger. As it turns out, an NSInteger is just a typedef for an int (via is it necessary to release a NSInteger in iphone? )


You will all release objects that extend NSObjects (or implement NSObject protocol).
please read http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html for better understanding of memory management.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜