Memory management in Core Data is a bit tricky.
If you don't do anything special with a transient property, then in most cases the synthesized accessors will manage the property's object life-cycle for you. (When Xcode generates the source for a managed object class from the data model, it doesn't bother to create a final release for the property's object. It would if it was always necessary.) Unfortunately, you're often doing something special with a transient property so you do need to release it or any other objects created in the process.
However, you don't release in dealloc. The Apple docs strongly recommend that you never modify either the init or the dealloc of NSManagedObject subclass. Instead, to release a transient property, you need to put the release in didTurnIntoFault
. The reason for this is that when Core Data converts an object to a fault, it purges all its attributes even though the object is still resident in memory and alive.
Because so much goes on behind the scenes with Core Data it is very important to check that the transient property's object is not nil before you send it a final release.