views:

36

answers:

2

Is a transient property a "managed property" in terms of Core Data? Does Core Data manage it's memory too? Or must I -release that manually in -dealloc?

(I think no, because I might choose to not create a subclass - but I guess it doesn't make sense when I have a transient property, since I need a subclass to calculate that derived value --- or not??)

+1  A: 

If your managed object allocates anything special at any time to support your transient property, then you should release that in dealloc. Basically, release anything that you create.

Jason Coco
You've got a major error here. With managed objects, you do not release in dealloc but instead `didTurnIntoFault`.
TechZen
+1  A: 

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.

TechZen
So even if I would release a transient property in -didTurnIntoFault, I would have to check like if(transientProperty != nil) {[transientProperty release]} ?? But: sending -release to nil is not a problem, though.... or is it?
dontWatchMyProfile
In theory no, in reality, I've seen some odd issues in core data that checking for nil seems to avoid. You can probably disregard that. Its more of my belt and suspenders attitude.
TechZen