提取时Coredata崩溃 [英] Coredata crash while fetching
问题描述
我在生产应用程序中遇到一些奇怪的coredata错误,并且我能够掌握崩溃报告。
I am getting some weird coredata error in the production app and I was able to get hold of the Crash Report.
有时会崩溃并显示以下消息
Its Crashing with the following message at times
***对象0x17e400000的错误:释放未分配的指针
*** error for object 0x17e400000: Freeing unallocated pointer
***对象0x17fd03730的错误:未分配指针重新分配
*** error for object 0x17fd03730: pointer being reallocated was not allocated
这是堆栈跟踪
Crashed: SQLQueue 0x13ff15250 for datastore.sqlite
SIGABRT ABORT 0x0000000183986014
0 libsystem_kernel.dylib __pthread_kill + 8
1 libsystem_pthread.dylib pthread_kill + 112
2 libsystem_c.dylib abort + 140
3 libsystem_malloc.dylib _nano_vet_and_size_of_live + 330
4 libsystem_malloc.dylib nano_free + 220
5 libsqlite3.dylib sqlite3_finalize + 244
6 CoreData -[NSSQLiteConnection _finalizeStatement] + 100
7 CoreData -[NSSQLiteConnection releaseSQLStatement] + 52
8 CoreData newFetchedRowsForFetchPlan_MT + 2420
9 CoreData _executeFetchRequest + 72
10 CoreData -[NSSQLFetchRequestContext executeRequestUsingConnection:] + 60
11 CoreData __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 260
12 libdispatch.dylib _dispatch_client_callout + 16
13 libdispatch.dylib _dispatch_barrier_sync_f_invoke + 84
14 CoreData -[NSSQLDefaultConnectionManager handleStoreRequest:] + 208
15 CoreData -[NSSQLCoreDispatchManager routeStoreRequest:] + 288
16 CoreData -[NSSQLCore dispatchRequest:withRetries:] + 200
17 CoreData -[NSSQLCore processFetchRequest:inContext:] + 108
18 CoreData -[NSSQLCore executeRequest:withContext:error:] + 504
19 CoreData __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 4512
20 CoreData -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 276
21 CoreData -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 408
22 CoreData -[NSManagedObjectContext executeFetchRequest:error:] + 572
23 CoreData -[NSManagedObjectContext(_NestedContextSupport) _parentObjectsForFetchRequest:inContext:error:] + 456
24 CoreData __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 584
25 CoreData internalBlockToNSManagedObjectContextPerform + 92
26 libdispatch.dylib _dispatch_client_callout + 16
27 libdispatch.dylib _dispatch_barrier_sync_f_invoke + 84
28 CoreData _perform + 232
29 CoreData -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 188
30 CoreData -[NSManagedObjectContext executeFetchRequest:error:] + 572
31 *MY_APP* NSManagedObject+MagicalRecord.m line 50__67+[NSManagedObject(MagicalRecord) MR_executeFetchRequest:inContext:]_block_invoke
它确实发生在主线程上,我对如何调试它感到困惑。虽然看起来像一个内存问题。同样,在使用工具时,遇到 NSPrivateQueueConcurrencyType
时,它会在应用程序中显示一些泄漏。
It did happen on the main thread and I am puzzled on how to debug this. Looks like a memory issue though. Also while using instruments its showing some leaks in the app when it comes across NSPrivateQueueConcurrencyType
.
应用正在广泛使用MagicalRecord,这是导致上述崩溃的应用中的代码块。它只是从主线程正常获取。最有趣的是,它随机崩溃,即它并不总是崩溃,但有时在获取时崩溃。
App is using MagicalRecord Extensively and here is the code block in the App Which leads to above crash. Its just a normal fetch from Main Thread. Most interestingly it crash randomly, ie it doesn't always crash but at times it crashes while doing a Fetch.
NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"code == %@ and pid == %@", aCode,pid];
Permission *aPermission = [Permission MR_findFirstWithPredicate:filterPredicate];
推荐答案
访问(写或 Read )在除 Managed Object Context Queue 之外的任何线程上的Managed Object导致未定义的行为&会导致随机的奇怪的崩溃。
看来您的托管对象上下文
是使用创建的NSPrivateQueueConcurrencyType
&您在主队列
上执行的获取
。这是奇怪崩溃的根源。
您可以使用 NSMainQueueConcurrencyType初始化
或将所有 MOC
fetchRequests
嵌套在 [MOC performBlock:{...}]
Accessing (Write or Read) a Managed Object on any thread other than the Managed Object Context Queue causes undefined behaviour & leads to random weird crashes.
It looks like your Managed Object Context
was created with NSPrivateQueueConcurrencyType
& your performing fetch
on the Main Queue
. This is the source of the weird crash.
You can either initialize MOC
with NSMainQueueConcurrencyType
or nest all your fetchRequests
inside [MOC performBlock:{...}]
这篇关于提取时Coredata崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!