2010-10-20 161 views
0

我有一個包含圖像數據作爲BLOB的SQLite數據庫,我使用下面的代碼來設置對象的屬性,但我得到的數據主要內存問題,特別是在和w.wineImage對象,儘管它看起來像我正確地釋放一切......SQLite +內存管理問題

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

回答

0

你發佈信息noImage但你這已經是自動釋放imageNamed創建它。

我不知道這是否有助於你的問題,但你絕對不應該這樣做:)