我控制器獲取數據:內存泄漏從功能delegat
- (NSArray *)getChapters {
NSMutableArray *list = [[NSMutableArray alloc] init]; //memory leak
if (chapter_statement == nil) {
const char *sql = "SELECT DISTINCT 'Глава '||chapter FROM verses WHERE book=? ORDER by chapter";
if (sqlite3_prepare_v2(database, sql, -1, &chapter_statement, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
}
sqlite3_bind_int(chapter_statement, 1, self.book);
while (sqlite3_step(chapter_statement) == SQLITE_ROW) {
NSString *body = [NSString stringWithUTF8String:(char *)sqlite3_column_text(chapter_statement, 0)];
[list addObject:body];
[body release];
}
sqlite3_reset(chapter_statement);
return list;
}
,並在控制器使用它:
- (void)viewWillAppear:(BOOL)animated {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.listChapters = [[NSArray alloc] initWithArray:[appDelegate getChapters]];
[self.listChapters release];
}
泄漏顯示了內存泄漏:NSMutableArray *list = [[NSMutableArray alloc] init];
如果我回來像return [list autorelease];
應用程序崩潰在viewWillAppear
。 如何解決這個問題?
是的,它的工作,但現在泄漏顯示泄漏 - [NSPlaceholderString initWithBytes:length:encoding:]在基金會 – 2010-07-20 17:52:50
我懷疑泄漏來自其他地方。如果您還沒有,請查看FMDB(http:// gusmueller。com/blog/archives/2008/06/new_home_for_fmdb.html)這是一個Sqlite的基本Cocoa包裝器,可以爲您節省很多管理數據庫調用的麻煩。 – 2010-07-21 05:42:45