I learned that if a @property
has the attribute retain
it should always be released in the dealloc
method. But if the program never allocates memory for the property this means we release an unallocated object, right? Does this mean that the property must be allocated in the init
method?
But if the program never allocates memory for the property this means we release an unallocated object, right?
Wrong. If you say [self->myVar release]
in dealloc
, then either myVar
has been assigned a value or it has not:
If it has, it is now released, which is what you want.
If it has not, it is nil
, and nothing happens and no harm done, because a message to nil
does nothing.