应用程序冻结CoreData保存 [英] App freeze on CoreData save

查看:99
本文介绍了应用程序冻结CoreData保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,冻结有时当保存CoreData然后不重新启动。我有一个使用数据库的第二个线程,但我认为我已经按照模式为该线程单独的上下文。这是重新启动的崩溃报告。任何想法?

I have an iPhone app that freezes sometimes when saving CoreData and then doesn't relaunch. I did have a second thread that uses the database, but I think I have followed the pattern to make a separate context for that thread. Here is the crash report from the relaunch. Any ideas?

我已经尝试将其更改为仅使用一个线程运行,这里是进入后台后的最新冻结点。

I have tried changing it to only run with one thread and here is the latest freeze point after entering the background.

#0  0x30851b98 in fsync
#1  0x3094e694 in _sqlite3_purgeEligiblePagerCacheMemory
#2  0x3094e6b8 in _sqlite3_purgeEligiblePagerCacheMemory
#3  0x30945372 in sqlite3_compileoption_get
#4  0x30957f06 in sqlite3_extended_errcode
#5  0x3095dc20 in sqlite3_extended_errcode
#6  0x3095dd8e in sqlite3_extended_errcode
#7  0x309646f8 in sqlite3_clear_bindings
#8  0x3098845a in sqlite3_open16
#9  0x3094495a in sqlite3_step
#10 0x31a1dc20 in _execute
#11 0x31acc6e8 in -[NSSQLiteConnection commitTransaction]
#12 0x31aca646 in -[NSSQLiteConnection endPrimaryKeyGeneration]
#13 0x31abeab4 in -[NSSQLCore prepareForSave:]
#14 0x31a4acd0 in -[NSSQLCore saveChanges:]
#15 0x31a1591e in -[NSSQLCore executeRequest:withContext:error:]
#16 0x31a1538a in -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
#17 0x31a48544 in -[NSManagedObjectContext save:]
#18 0x000080aa in -[KPersistence saveManagedObjects:] at KPersistence.m:242
#19 0x00004320 in -[KinKastAppDelegate applicationDidEnterBackground:] at KinKastAppDelegate.m:126

这是我的saveManagedObjects实现

Here is my implementation of saveManagedObjects

-(BOOL)saveManagedObjects:(NSError **)error
{
    [persistentStoreCoordinator lock];
    BOOL success = YES;
    if (managedObjectContext != nil) {
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:error]) {
            VLog(@"Unresolved error %@, %@", *error, [*error userInfo]);
            success = NO;
        } 
    }
    [persistentStoreCoordinator unlock];
    return success;
}


推荐答案

是我有时写一个带有浮点值的NSNumber到整数字段。这导致内存中的副本与从数据库读取的副本不同,这导致无限合并循环。但是如果你重新启动应用程序,它工作正常,因为值是一个整数从那时起。

So I now believe the problem was that I was sometimes writing an NSNumber with float value to an integer field. This caused the copy in memory to be different than the copy read from the database, and this caused the infinite merge loop. But if you restarted the app it worked fine because the value was simply an integer from then on.

这篇关于应用程序冻结CoreData保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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