3
votes

for Xcode produced Core Data managed objects, do I need to add a dealloc method to release variables?

So when I have a core data model for my iPhone app, and I let XCode generate the managed object classes, I note there is no dealloc method. Do I need to "release" in a dealloc method myself manually to the variables/properties?

I see the code-generated managed object classes have:

  • the property is marked "retain" in the header file
  • in the implementation file it is set up with "@dynamic" (i.e. not @sythesise)

thanks

3

3 Answers

4
votes

You don't need to (and shouldn't) modify these generated files. The @dynamic means that the property implementations will be provided at runtime. Dynamic Properties

3
votes

There's two parts to this. For the attributes that you define in you're model, don't release them in a dealloc method. Core Data is managing those for you. But if you add other ivars to the class that gets generated, say you have an imageData attribute and then make a UIImage out of it that you hold in your NSManagedObject subclass, then you need to add the dealloc method and release it like you would in any other object.

I'd highly recommend you start using mogenerator. It's nice since it generates a machine file and a user file to keep the stuff that's handled automatically for you separate from your custom code.

0
votes

While you do not need to release Core Data managed properties, you should clean up any properties or instance variables your custom Core Data subclass creates. However, you cannot rely on dealloc to be called on Core Data subclasses. Use willTurnIntoFault to perform any cleanup necessary.