SQLite +内存管理问题

时间:2010-10-20 16:34:56

标签: iphone objective-c memory-management

我有一个包含图像数据的SQLite数据库作为BLOB,我使用以下代码来设置对象的属性,但是我遇到了数据的主要内存问题,特别是在dataw.wineImage个对象,即使看起来我正在正确释放所有内容......

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);

1 个答案:

答案 0 :(得分:0)

您正在发布noImage,但是您已经从已经自动释放的imageNamed创建了它。

我不知道这是否有助于解决您的问题,但您绝对不应该这样做:)