What is the most efficient way to delete a large number (10.000+) objects in Core Data?

后端 未结 6 1342
青春惊慌失措
青春惊慌失措 2020-12-17 01:07

The way I\'m trying to delete multiple sets of 10.000+ NSManagedObjects is just too memory intensive (around 20MB live bytes), and my app is being jettisoned. Here is the im

6条回答
  •  温柔的废话
    2020-12-17 01:57

    In a moment of inspiration, I removed [fetch setIncludesPropertyValues:NO]; and it was good. From the docs:

    During a normal fetch (includesPropertyValues is YES), Core Data fetches the object ID and property data for the matching records, fills the row cache with the information, and returns managed object as faults (see returnsObjectsAsFaults). These faults are managed objects, but all of their property data still resides in the row cache until the fault is fired. When the fault is fired, Core Data retrieves the data from the row cache—there is no need to go back to the database.

    I managed to reduce allocated live bytes to ~13MB, which is better.

提交回复
热议问题