Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Core Data manages object lifetimes the same way the rest of Cocoa manages object lifetimes: NSManagedObject instances in a managed object context are retained in memory as long as the managed object context <em>or any other object</em> retains ownership of them (via <code>-[NSObject retain]</code>. By default, the <code>NSManagedObjectContext</code> does not retain instances, so they are released as soon as any other owners (i.e. your <code>NSFetchedResultsController</code> instances or other instances in your program) release them. You can change this default behavior of the managed object context to retain instances, but you rarely want to. The managed object context <em>has</em> to retain instances that are updated until the next save. There's no way to preserve these changes except in the object instance until the context is saved. So, to minimize memory usage of Core Data objects, follow the standard rules: release them as soon as you can. If you find that your context memory usage is growing (use Instruments' Core Data instruments to track this), save the context more frequently if you are updating instances and hence keeping them alive in the context until the next save even if you've otherwise released them.</p> <p>Using <code>NSFetchedResultsController</code> makes all of this easier. In fact, the reason <code>NSFetchedResultsController</code> exists at all is to make batch fetching in a low memory environment (like the iPhone) easier for the programmer.</p> <p>As Louis mentioned, the <code>NSPersistentStoreCoordinator</code> maintains a row cache to cache instance data in memory instead of having to go back to disk when an object is faulted into the managed object context. This is a Core Data implementation detail, however (though cache misses are a performance hit; you can track cache misses in Instruments). Core Data manages the cache memory and you shouldn't have to worry about it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload