Re: CoreData retain/release/delete
Re: CoreData retain/release/delete
- Subject: Re: CoreData retain/release/delete
- From: Scott Stevenson <email@hidden>
- Date: Fri, 29 Apr 2005 13:03:59 -0700
On Apr 29, 2005, at 12:49 PM, John Brownlow wrote:
That almost answers my question.
But I am concerned about managedObjects whose retain count falls to
zero, but which are *not* explicitly deleted using -deleteObject.
You really don't need to worry about stuff like that. The context
handles the availability of the actual objects in memory.
Are these automatically deleted from the persistent store on save, or
do they hang around?
If you delete an object and save, I goes away from the persistent store
and eventually gets dealloc'd.
I create a lot of objects with many relationships which I do not want
to track manually. Once they are released from all relationships and
their retain count falls to zero, I want them to be deleted from the
persistent store since I have no further use for them.
This gets a lot of easier of you don't think about retain counts at
all. In fact, an object at a particular place in memory could
theoretically be released (and later re-alloc'd) with any deletion at
all. Core Data abstracts you from the process of basic memory
management.
An example of this might be a 'sequence' object, which is an ordered
collection of 'scene' objects. Once a sequence has lost all of its
scenes and has been removed from any parent sequences, its
retain-count will be zero and I would like it to be removed from the
persistent store on the next save
Hmmm... typically you want to use cascading, but it sounds like it
probably won't work here.
Your best bet might be to create a custom subclass of NSManagedObject
and implement -removeScenes: and/or -removeSceneObject: (don't hold me
to the exact names). Core Data will call these to remove scenes from
the relationship.
Inside that method, you could check to see if there will be any more
scenes after the current set is removed. If not, you can delete 'self'.
This isn't incredibly elegant, but I'm not aware of a better solution.
You can control-click on an Entity in the model to get a custom class
generated for you. Should be easier to figure this by doing that.
- Scott
--
http://treehouseideas.com/
http://theocacao.com/ [blog]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden