If I have a class
@interface Foo {
NSString *temp;
}
@property(nonatomic, copy) NSString *temp;
@end
I understand that upon assignment, the old temp will get released and the new one will be assigned using temp = [newTemp copy]. And going by memory management rules, you are supposed to do [temp release] in the dealloc method of Foo, right?
What I don’t understand is what happens if the setter was never used – you still have the [temp release] in the dealloc, so it’s releasing something with a retain count of 0. Can someone clarify this for me?
There are two possibilities.
Since you never set it, it’s
nil. Sendingreleasetonilis just fine. So no problem there.Your
initroutine makes a default value fortemp. Then it is a real object, and sending itreleaseis also ok.No problem all around! In neither case are you sending a message to an object with a retain count of 0.