I am having some memory issues with this method. courseNames, iDString and tempData are leaking, but nameString does not seem to be leaking. Can someone explain to me how to prevent this from happening
Code:
+(NSMutableArray *)selectNamesAndID{
NSString *query = [[NSString alloc] initWithFormat: @"SELECT Name, ID FROM Courses"];
[query autorelease];
sqlite3_stmt *statement;
NSMutableArray *courseNames = [[NSMutableArray alloc] init];
[courseNames autorelease];
int result = (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, NULL));
NSString *nameString;
NSString *iDString;
NSArray *tempData;
while(sqlite3_step(statement) == SQLITE_ROW){
char *nameChar = (char *)sqlite3_column_text(statement, 0);
nameString = [[NSString alloc] initWithUTF8String:nameChar];
int iDInt = sqlite3_column_int(statement, 1);
iDString = [[NSString alloc] initWithFormat:@"%d", iDInt];
tempData = [[NSArray alloc] initWithObjects:nameString, iDString, nil];
[tempData autorelease];
[courseNames addObject:tempData];
[tempData release];
[nameString release];
[iDString release];
}
sqlite3_finalize(statement);
return courseNames;
}