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:
You only need to retain and release objects. BOOLs and NSIntegers are not objects, they're primitives.
You generally shouldn't call
release
for anyassign
property, because you haven't retained it — and of courseassign
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.
精彩评论