objective-cretain

Do we always have to allocate a @property with the retain attribute?


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?


Solution

  • 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: