cowfaboo
cowfaboo

Reputation: 709

Simple memory management with core data and ARC

I am still getting used to some of the details of memory management in objective-c, despite the fact that ARC simplifies things significantly. Here is a line of code:

[song addEntriesObject:self.entry];

where song is a managed object that I access by executing a fetch request on my managed object context, and self.entry refers to an instance variable that is passed into this class upon initialization, and is also a managed object (i.e. it's a core data entity - hope I'm using that terminology properly).

My question is simply whether this will cause any problems in memory management, i.e. whether assigning self.entry to a managed object will prevent that instance variable from being released because it is being retained by core data, or something along those lines. Would this create any problems, or does core data not maintain pointers to objects in the same way? Or am I just completely on the wrong track with my thought process here?

Any thoughts on the subject would be much appreciated.

Upvotes: 0

Views: 694

Answers (1)

adonoho
adonoho

Reputation: 4329

cowfaboo,

Core Data objects are NSObjects and hence behave identically. In other words, nothing changes with respect to memory management. In your example, self.entry is retained by both your instance and by song.

Independent of ARC, Core Data items can retain large object graphs. These may need to be pruned. The -refreshObject:mergeChanges: method is used to do this. To save yourself some pain, you should always use -save: before trimming your graph.

Andrew

Upvotes: 2

Related Questions