Hi, My controller get data from function in 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;
}
and use it in controller:
- (void)viewWillAppear:(BOOL)animated {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.listChapters = [[NSArray alloc] initWithArray:[appDelegate getChapters]];
[self.listChapters release];
}
Leaks shows a memory leak at : NSMutableArray *list = [[NSMutableArray alloc] init]; If I do return like return [list autorealise]; app crashes in viewWillAppear. How to fix this problem?