views:

14

answers:

1

I have a SQLite database containing image data as a BLOB, and I am using the follow code to set the properties of an object, but I am getting major memory issues with the data, particularly on the data and w.wineImage objects, even though it looks like I am releasing everything correctly...

if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

            while(sqlite3_step(selectstmt) == SQLITE_ROW) {
                Wine *w = [[Wine alloc] init];  

                w.wineId = sqlite3_column_int(selectstmt, 0);
                w.wineName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];

                NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selectstmt, 2) length:sqlite3_column_bytes(selectstmt, 2)];

                if([data length] < 10){                     
                    UIImage *noImage = [UIImage imageNamed:@"no_image.png"];                
                    w.wineImage = noImage;
                    [noImage release];
                    [data release];
                } else {
                    UIImage *wineBottle = [[UIImage alloc] initWithData:data];
                    w.wineImage = wineBottle;
                    [wineBottle release];
                    [data release];
                }           

                w.price = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];


                [wineArray addObject:w];
                //w=nil;


                [w release];

            }

            sqlite3_close(database);
A: 

You're releasing noImage but you created it from imageNamed which is already autoreleased.

I don't know if that helps your problem but you definitely shouldn't be doing it :)

deanWombourne