I've been using Instruments to try and reduce my app's memory footprint. Running in "Profile" mode and selecting the Leaks option whilst marking generations, I have noticed that my SQLite database class is retaining variables which is leading to memory growth. Since my app will be calling these functions thousands of times during its update process it starts to turn into a bigger problem.
The first function simply prepares the SQL statement and binds any variables there might be:
- (BOOL)prepare:(NSString *)sql withBindings:(NSArray *)bindings {
if (! sqlite3_prepare_v2(_db, [sql UTF8String], -1, &_statement, NULL) == SQLITE_OK) {
return NO;
}
for (int i = 0; i < [bindings count]; i++) {
sqlite3_bind_text(_statement,
i + 1,
[bindings[i] isKindOfClass:[NSNull class]]
? [@"" UTF8String]
: [bindings[i] UTF8String],
-1,
SQLITE_TRANSIENT);
}
return YES;
}
which gives the following information:
- 0 libsystem_malloc.dylib malloc_zone_malloc
- 1 libsqlite3.dylib 0x1958cf588
- 2 libsqlite3.dylib 0x1958d7f68
- 3 libsqlite3.dylib 0x19591cc58
- 4 libsqlite3.dylib 0x195905728
- 5 libsqlite3.dylib 0x1958d0614
- 6 libsqlite3.dylib 0x19592a934
- 7 app -[Db prepare:withBindings:] app/Db.m:68
- 8 app -[Update update] app/Update.m:208
- 9 app __57-[AppDelegate application:didFinishLaunchingWithOptions:]_block_invoke_2 app/AppDelegate.m:70
- 10 libdispatch.dylib _dispatch_call_block_and_release
- 11 libdispatch.dylib _dispatch_client_callout
- 12 libdispatch.dylib _dispatch_queue_drain
- 13 libdispatch.dylib _dispatch_queue_invoke
- 14 libdispatch.dylib _dispatch_root_queue_drain
- 15 libdispatch.dylib _dispatch_worker_thread3
- 16 libsystem_pthread.dylib _pthread_wqthread
- 17 libsystem_pthread.dylib start_wqthread
The second function simply steps through the row:
- (BOOL)stepThrough {
return sqlite3_step(_statement) == SQLITE_ROW;
}
which gives the following information:
- 0 libsystem_malloc.dylib malloc_zone_malloc
- 1 libsqlite3.dylib 0x1958cf588
- 2 libsqlite3.dylib 0x1958d7f68
- 3 libsqlite3.dylib 0x19591cc58
- 4 libsqlite3.dylib 0x195905728
- 5 libsqlite3.dylib 0x195914a0c
- 6 libsqlite3.dylib 0x195906dc8
- 7 libsqlite3.dylib sqlite3_step
- 8 poc -[Db stepThrough] app/Db.m:79
- 9 poc -[Update update] app/Update.m:208
- 10 poc __57-[AppDelegate application:didFinishLaunchingWithOptions:]_block_invoke_2 app/AppDelegate.m:70
- 11 libdispatch.dylib _dispatch_call_block_and_release
- 12 libdispatch.dylib _dispatch_client_callout
- 13 libdispatch.dylib _dispatch_main_queue_callback_4CF
- 14 CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE_
- 15 CoreFoundation __CFRunLoopRun
- 16 CoreFoundation CFRunLoopRunSpecific
- 17 GraphicsServices GSEventRunModal
- 18 UIKit UIApplicationMain
- 19 poc main app/main.m:16
- 20 libdyld.dylib start
Hopefully that is enough information for someone to say "Oh, you've an extra retain count there", but if you need any more than please do let me know.
Aucun commentaire:
Enregistrer un commentaire