Hi, I have searched high and low to try to resolve this memory leak, but I can't figure out how to make it go away. I have several classes that I use to connect to my sqlite dbase and pull information.
When I run the app using performance tools, leaks, I keep finding that all of my classes leak memory.
Below is the code that I have. Any help resolving this leak would be greatly appreciated.
tbl_materialsList.h
@interface tbl_materialsList : NSObject {
NSInteger materialListID;
NSString *shoppingListID;
NSString *projectID;
NSString *materialName;
NSString *numberOfUnits;
NSString *purchased;
NSString *totalPrice;
NSString *unitPrice;
}
@property (nonatomic, readonly) NSInteger materialListID;
@property (nonatomic, retain) NSString *shoppingListID;
@property (nonatomic, retain) NSString *projectID;
@property (nonatomic, retain) NSString *materialName;
@property (nonatomic, retain) NSString *numberOfUnits;
@property (nonatomic, retain) NSString *purchased;
@property (nonatomic, retain) NSString *totalPrice;
@property (nonatomic, retain) NSString *unitPrice;
- (id)getDataToDisplay:(NSString *)dbPath :(NSString *)selectStatement;
- (void)saveData:(NSString *)dbPath :(NSString *)selectStatement;
- (id)initWithPrimaryKey:(NSInteger)pk;
tbl_materialsList.m
- (id)getDataToDisplay:(NSString *)dbPath :(NSString *)selectStatement {
// Init the data Array
NSMutableArray *data = [[NSMutableArray alloc] init];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
NSString *sql = selectStatement; //"select * from tbl_projects";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &selectstmt, NULL) == SQLITE_OK) {
//loop thru and fill the array
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
//reading the results
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
tbl_materialsList *listObj = [[tbl_materialsList alloc] initWithPrimaryKey:primaryKey];
listObj.shoppingListID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
listObj.projectID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
listObj.materialName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
listObj.numberOfUnits = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];
listObj.purchased = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];
listObj.totalPrice = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)];
listObj.unitPrice = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 7)];
[data addObject:listObj];
[listObj release];
}
}
//release the compiled statment from memory
sqlite3_finalize(selectstmt);
}
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
return data;
}