I have this property synthesized and declared in my class ‘ClassA’
@interface ClassA
@property (nonatomic, retain) NameFieldCell* nameCell;
@end
I know that the rule says that the nameCell property should be released in my dealloc method when it is declared with retain|copy|…
However, ‘ClassA’ gets instantiated lazily and sometimes the nameCell property is not even used, which means that I don’t use its setter method nor access it nor retain it explicitly.
Should I still be calling [nameCell release] in my dealloc method? I find it difficult to understand that I should be releasing something that is not even initialized. And since it is not initialized, the reference counter is 0 and makes no sense to release it? Or is nameCell somehow retained automatically when instantiating ‘ClassA’ even if I am not making use of it?
In Objective-C, the memory allocated by
allocfor a class is initialized to all-bits-zero on allocation (and then theisaivar is set), which results innameCell‘s backing ivar being set tonilby default. And since it is not an error to send a message tonilin Objective-C (the message is just ignored), you are free to just call[nameCell release]without worrying about whethernameCellwas ever set.