Why shouldn’t I use the getter to release a property in objective-c?

For a retained property with no custom accessor, you can release the object by:

self.variable = nil;

This has the effect of setting the ivar (which may not be called ‘variable’ if you have only declared properties) to nil and releasing the previous value.

As others have pointed out, either directly releasing the ivar (if available) or using the method above is OK – what you must not do is call release on the variable returned from a getter.

Leave a Comment