fmdb
fmdb copied to clipboard
Avoiding crash in FMResultSet
Hi Guys, I found the crash and solution. Just add the @autorelease { } to method FMDatabaseQueue.m:
- (void)beginTransaction:(FMDBTransaction)transaction withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block { inside in dispatch_sync(_queue, ^() { block.
In my project I have 25 tables, each in different .db files, and 25 FMDatabaseQueue. Application can intensively read from databases (25 parallel requests from many threads). If @autoreleasepool missing in beginTransaction, the ARC can manage deallocation of FMResultSet after main method will finished (after exiting from RunLoop). In dealloc, FMResultSet has access to database, but already other FMDatabaseQueue can have exclusive access to sql and it produce crash.
If you add @autoreleasepool inside beginTransaction, all FMResultSet objects will be deallocated exactly after exiting from block() or after exiting from beginTransaction method and not be crashed app, when other FMDatabaseQueue has access. =)
Why wouldn't you add the autorelease inside the block you're using?
I also met same issue,and it only happened on iPhone X(iOS 12 or iOS 11.4),is it the same to you?
thread stacktrace attached belowed:
1upchat 0x100521ea0 pcache1FetchStage2 (sqlite3.c:46418)
2upchat 0x10052184c pcache1Fetch (sqlite3.c:46558)
3upchat 0x10052184c pcache1Fetch (sqlite3.c:46558)
4upchat 0x1004adeac sqlite3PagerGet (sqlite3.c:45121)
5upchat 0x1004df6cc getAndInitPage (sqlite3.c:60604)
6upchat 0x1004dd790 sqlite3BtreeMovetoUnpacked (sqlite3.c:63879)
7upchat 0x1004def44 handleDeferredMoveto (sqlite3.c:73803)
8upchat 0x1004d9c8c sqlite3VdbeExec (sqlite3.c:73867)
9upchat 0x1004b6d3c sqlite3_step (sqlite3.c:75900)
10upchat 0x1005a008c -[FMResultSet nextWithError:] (FMResultSet.m:161)
11upchat 0x1002c095c __44+[UPCSQLPreferencesHelper preferenceForKey:]_block_invoke (UPCSQLPreferencesHelper.m:107)
12upchat 0x10059d4f4 __30-[FMDatabaseQueue inDatabase:]_block_invoke (FMDatabaseQueue.m:162)
13libdispatch.dylib0x180839474