我使用FMDB从SQLite中提取记录并将其添加到Core Data,后者配置为与iCloud同步。这适用于少量数据,但是当迁移数千条记录时,我会收到崩溃的内存警告:
收到内存警告。
...和iCloud同步错误:
CoreData:iCloud:错误:无法在90秒内收到初始同步通知回调
我正在尝试优化迁移,以便我不会耗尽内存。我看过Reducing Memory Overhead,但我对此并不了解。
这是我的代码,在后台线程中运行:
FMDatabaseQueue *queueOld = [FMDatabaseQueue databaseQueueWithPath:oldDatabasePath];
[queueOld inTransaction:^(FMDatabase *dbqOld, BOOL *rollback) {
//(1) Query that extracts the aircraft data from the old database
FMResultSet *aircraftResults = [dbqOld executeQuery:@"<SELECT ALL THE RECORDS...>"];
//(2) Walk through each row returned from the database
while ([aircraftResults next]){
//(3) Create a new Core Data Aircraft NSManagedObject
Aircraft *aircraft = [[PPCoreData myCoreData] createEntity:@"Aircraft"];
aircraft.aircraftRegistration = [aircraftResults stringForColumn:@"aircraftRegistration"];
aircraft.makeModel = [aircraftResults stringForColumn:@"aircraftMakeModel"];
//etc...
}
[aircraftResults close];
}];
//(4) Save to Core Data
[[PPCoreData myCoreData] save]; //"myCoreData" is a singleton that has all my Core Data goods
我应该更频繁地保存到核心数据吗?这会让我的记忆力下降吗?
我还能做些什么来提高内存效率吗?
提前致谢。