How do i avoid running out of memory when performing a task on every item of core data?

后端 未结 2 1259
不知归路
不知归路 2021-01-29 03:32

I\'m trying to perform a task similar to this:

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@\"Entry\"];

        NSPredicate *predicate          


        
2条回答
  •  囚心锁ツ
    2021-01-29 04:16

    This is a perfect case for using an @autoreleasepool

    Place an @autoreleasepool around all the code which gets executed in your loop. This will automatically release the objects after they get processed so your memory footprint stays low. If using this technique you shouldn't have to specify a batch size.

    See the apple docs here for more information;

    https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html

提交回复
热议问题