核心数据迁移崩溃 [英] Crash on Core Data Migration

查看:151
本文介绍了核心数据迁移崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一些用户在Core Data迁移时崩溃。



已经有几个关于核心数据迁移和崩溃的问题,主要是关于内存使用和UI响应。



迁移大型核心数据数据库崩溃



在进行核心数据迁移时出现内存不足



核心数据导致应用程序在迁移时崩溃



处理数据轻量级迁移崩溃



对于高内存峰值,Apple建议多遍解决方案,这里是另一个大型数据集解决方案



当我尝试重现问题时,像使用轻量级迁移迁移大型数据集,Xcode有时由于内存使用而终止我的应用程序。



但是,@Marcus S. Zarra告诉我:


@Jason Lee:轻量级迁移不会耗尽内存。也许你会混淆它与一个坏的食物崩溃或其他?我建议开一个新的SO问题,并发送给我的链接。 - Marcus S. Zarra


我创建这个新问题:


  1. 如何判断应用程序在核心数据迁移时崩溃的原因?
    内存问题或无UI回应。

  2. 如何解决问题?

感谢。



更新1:添加崩溃日志



@Marcus S. Zarra,你是对的。 ATE BAD FOOD ...

 日期/时间:2014-01-03 15:15: 00.801 +0800 
操作系统版本:iPhone OS 5.1.1(9B206)
报告版本:104

异常类型:00000020
异常代码:0x8badf00d
突出显示的线程:0

应用程序特定信息:
com.xxx.xxx未能及时启动

已用总CPU时间(秒):7.330 ,系统0.000),36%CPU
经过的应用程序CPU时间(秒):4.387,21%CPU

线程0名称:分派队列:com.apple.main-thread
线程0:
0 libsqlite3.dylib 0x317ae6ba ___ lldb_unnamed_function176 $$ libsqlite3.dylib + 166
1 libsqlite3.dylib 0x317a2846 ___ lldb_unnamed_function128 $$ libsqlite3.dylib + 7934
2 libsqlite3.dylib 0x317a06c2 sqlite3_step + 2098
CoreData 0x36924e2e _execute + 50
4 CoreData 0x36924d64 - [NSSQLiteConnection execute] + 2408
5 CoreData 0x369c7d54 - [NSSQLConnection prepareAndExecuteSQLStatement:] + 40
6 CoreData 0x36a19582 - [_ NSSQLiteStoreMigrator performMigration :] + 590
7 CoreData 0x36a102b8 - [NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1948
8 CoreData 0x369b5c02 - [NSMigrationManager migrateStoreFromURL:type:options:withMappingModel :toDestinationURL:destinationType:destinationOptions:error:] + 482
CoreData 0x36a01bf4 - [NSStoreMigrationPolicy(InternalMethods)migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 176
10 CoreData 0x36a0119c - [NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 84
11 CoreData 0x36a02b58 - [NSStoreMigrationPolicy(InternalMethods)_gatherDataAndPerformMigration:] + 2188
12 CoreData 0x3691a20e - [NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error :] + 3086

那么,异步迁移数据?



stackoverflow.com/questions/2160848/core-data-causing-app-to-crash-while-migrating\">使应用程序崩溃时迁移,不是内存崩溃。这是一个看门狗崩溃。



迁移大型Core Data数据库崩溃没有崩溃日志,但我怀疑它可能是一个看门狗。



Core Data轻量级迁移崩溃也是一个看门狗崩溃,而不是内存崩溃。



一旦我们看到您的崩溃,就可以看到发生了什么。



更新1



Ok, 0x8badf00d 是我们的看门狗崩溃。这意味着您的应用程序启动时间太长。



如何解决这个问题?



不要站在 -applicationDidFinishLaunching ... 是简短的答案。



快速修复是让应用程式的初始检视画面与启动画面(启动画面)完全相同。然后,当你启动它快速(非常快)完成 -applicationDidFinish ... ,你可以采取只要你想迁移。



我的建议(因为你不知道迁移需要多长时间才能开始:


  1. 使用 - [NSManagedObjectModel isConfiguration:compatibleWithStoreMetadata:] 检查是否需要迁移

  2. 更新视图显示以让用户知道正在进行迁移

  3. 在后台块中进行迁移(将 -addPersistentStore ... 在一个块中,并在后台队列上调用它,它是线程安全的,虽然最好把锁定在它周围。)

  4. 当迁移时删除临时视图完成


  5. 足够容易改变,让你通过看门狗。


    Some of our users crash on Core Data migration.

    There are already several questions about "Core Data Migration & crash", mainly about memory usage and UI response.

    Migrating large Core Data database crash

    Out-Of-Memory while doing Core Data migration

    Core Data causing app to crash while migrating

    Core Data lightweight migration crash

    For high memory peak, Apple suggests multiple passes solution, and here is another large datasets solution.

    When I try to reproduce the problem, like migrating large datasets using lightweight migration, Xcode will sometimes terminate my app due to memory usage. So I think that our users may come across crash due to the same reason - low memory.

    But, @Marcus S. Zarra told me :

    @Jason Lee: Lightweight migration doesn't run out of memory. Perhaps you are confusing it with a bad food crash or something else? I would suggest opening a new SO question and sending me the link. – Marcus S. Zarra

    So I create this new question to ask:

    1. How to tell the reason when the app crash on Core Data Migration? Memory problem or no UI response.
    2. How to solve the problem?

    Thanks .

    UPDATE 1: add crash log

    @Marcus S. Zarra , you are right. ATE BAD FOOD...

    Date/Time:       2014-01-03 15:15:00.801 +0800
    OS Version:      iPhone OS 5.1.1 (9B206)
    Report Version:  104
    
    Exception Type:  00000020
    Exception Codes: 0x8badf00d
    Highlighted Thread:  0
    
    Application Specific Information:
    com.xxx.xxx failed to launch in time
    
    Elapsed total CPU time (seconds): 7.330 (user 7.330, system 0.000), 36% CPU 
    Elapsed application CPU time (seconds): 4.387, 21% CPU
    
    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0:
    0   libsqlite3.dylib                0x317ae6ba ___lldb_unnamed_function176$$libsqlite3.dylib + 166
    1   libsqlite3.dylib                0x317a2846 ___lldb_unnamed_function128$$libsqlite3.dylib + 7934
    2   libsqlite3.dylib                0x317a06c2 sqlite3_step + 2098
    3   CoreData                        0x36924e2e _execute + 50
    4   CoreData                        0x36924d64 -[NSSQLiteConnection execute] + 2408
    5   CoreData                        0x369c7d54 -[NSSQLConnection prepareAndExecuteSQLStatement:] + 40
    6   CoreData                        0x36a19582 -[_NSSQLiteStoreMigrator performMigration:] + 590
    7   CoreData                        0x36a102b8 -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1948
    8   CoreData                        0x369b5c02 -[NSMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 482
    9   CoreData                        0x36a01bf4 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 176
    10  CoreData                        0x36a0119c -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 84
    11  CoreData                        0x36a02b58 -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 2188
    12  CoreData                        0x3691a20e -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 3086
    

    So, migrate the data asynchronously?

    解决方案

    Starting an answer to update while we work through this.

    causing app to crash while migrating, is not a memory crash. That is a watch dog crash.

    Migrating large Core Data database crash has no crash log but I suspect it is probably a watchdog as well.

    Core Data lightweight migration crash is a watchdog crash as well, not a memory crash.

    Once we see your crash we can see what is going on.

    Update 1

    Ok, 0x8badf00d is our watch dog crash. This means your app is taking too long to launch.

    How to fix this?

    Don't stand up the core data stack in -applicationDidFinishLaunching... is the short answer.

    A quick fix is to have the initial view of your app be identical to the launch image (i.e. splash screen). Then when you launch it finishes -applicationDidFinish... quickly (very quickly) and you can take as long as you want to migrate.

    My recommendation (since you don't know how long the migration is going to take is to kick off is to:

    1. Check to see if a migration is necessary with -[NSManagedObjectModel isConfiguration: compatibleWithStoreMetadata:]
    2. Update the view display to let the user know that a migration is occurring
    3. Do the migration in a background block (put the -addPersistentStore... in a block and call it on a background queue, it is thread safe although it is best to put locks around it).
    4. Remove the temporary view when the migration is complete
    5. Launch your real UI.

    That should be easy enough to change and gets you past the watchdog.

    这篇关于核心数据迁移崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆