Hello,

I know, I am touching a hot iron, when claiming that sqlite might have a memory 
leak. But I am trying to debug memory leaks related to sqlite now since 4 days 
and I am running against walls.
Here is my problem:

- I am writing an iPhone app using iOS 8.2, Xcode 4.2, sqlite 3.8.8.3.

- The memory leak appears in the iPhone simulator more often, than on an 
original iPhone device, but it appears always.

- The leak appears with totally different type of queries. It might be, that a 
leak appears in a specific query in one debug session and in another debug 
session, it doesn?t (which makes it difficult to debug and drives me totally 
nuts). For me it seems to be related to a timing/threading issue. This is why 
it makes not much sense to offer some code here.

- When debugging inside sqlite the leak is always related to the same code 
line, independent from the type of database command (select, insert, delete).

- It appears always with the memory allocation in sqlite.c line 16872 in 
function sqlite3MemMalloc
 Here is the line: void *p = SQLITE_MALLOC( nByte );

- The leaked memory has always a size of nByte = 4344 bytes.

- Here is a typical call stack up to the leaked code:

  0 libsystem_malloc.dylib malloc_zone_malloc
  1 MYAPP sqlite3MemMalloc sqlite3.c:16872
  2 MYAPP mallocWithAlarm sqlite3.c:20510
  3 MYAPP sqlite3Malloc sqlite3.c:20541
  4 MYAPP pcache1Alloc sqlite3.c:39749
  5 MYAPP pcache1AllocPage sqlite3.c:39833
  6 MYAPP pcache1FetchStage2 sqlite3.c:40266
  7 MYAPP pcache1Fetch sqlite3.c:40367
  8 MYAPP sqlite3PcacheFetch sqlite3.c:39119
  9 MYAPP sqlite3PagerAcquire sqlite3.c:46573
 10 MYAPP btreeGetPage sqlite3.c:54380
 11 MYAPP getAndInitPage sqlite3.c:54435
 12 MYAPP moveToRoot sqlite3.c:57233
 13 MYAPP sqlite3BtreeMovetoUnpacked sqlite3.c:57465
 14 MYAPP sqlite3VdbeExec sqlite3.c:74055
 15 MYAPP sqlite3Step sqlite3.c:68839
 16 MYAPP sqlite3_step sqlite3.c:68905
 17 MYAPP -[FMResultSet nextWithError:] FMResultSet.m:155
 18 MYAPP -[FMResultSet next] FMResultSet.m:150
 19 MYAPP __40-[MYAPPAppDelegate loadPreferences]_block_invoke 
MYAPPAppDelegate.m:323
 20 MYAPP __30-[FMDatabaseQueue inDatabase:]_block_invoke FMDatabaseQueue.m:150
 21 libdispatch.dylib _dispatch_client_callout
 22 libdispatch.dylib _dispatch_barrier_sync_f_invoke
 23 MYAPP -[FMDatabaseQueue inDatabase:] FMDatabaseQueue.m:147
 24 MYAPP -[MYAPPAppDelegate loadPreferences] MYAPPAppDelegate.m:321
 25 MYAPP -[MYAPPAppDelegate application:didFinishLaunchingWithOptions:] 
MYAPPAppDelegate.m:157
 26 UIKit -[UIApplication 
_handleDelegateCallbacksWithOptions:isSuspended:restoreState:]
 27 UIKit -[UIApplication 
_callInitializationDelegatesForMainScene:transitionContext:]
 28 UIKit -[UIApplication _runWithMainScene:transitionContext:completion:]
 29 UIKit -[UIApplication workspaceDidEndTransaction:]
 30 FrontBoardServices __31-[FBSSerialQueue performAsync:]_block_invoke
 31 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
 32 CoreFoundation __CFRunLoopDoBlocks
 33 CoreFoundation __CFRunLoopRun
 34 CoreFoundation CFRunLoopRunSpecific
 35 UIKit -[UIApplication _run]
 36 UIKit UIApplicationMain
 37 MYAPP main main.m:16
 38 libdyld.dylib start

Does anybody have an idea how to debug something like this? Any help would be 
highly appreciated.

Best regards

Matthias Schmitt

magic moving pixel s.a.
23, Avenue Grande-Duchesse Charlotte
L-3441 Dudelange
Luxembourg
Phone: +352 54 75 75
http://www.mmp.lu




Reply via email to