2012-08-23 3 views
0

제발 도와주세요, 나는 정말로 메모리 누수 문제로 고민하고 있습니다. 다음은 내 코드입니다iPhone 응용 프로그램의 메모리 문제

+ (void) getInitialDataToDisplay:(NSString *)dbPath { 

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [appDelegate.itemArray removeAllObjects]; //0.8% 
    if (sqlite3_open([dbPath UTF8String], &dataBase) == SQLITE_OK) //18.9% 
    { 
     NSString *sqlStr = @"select * from ItemTable order by Status_id asc, ReleaseDate desc"; 
     const char *sql = [sqlStr UTF8String]; 
     sqlite3_stmt *selectstmt; 
     if(sqlite3_prepare_v2(dataBase, sql, -1, &selectstmt, NULL) == SQLITE_OK) { //25% 
      while(sqlite3_step(selectstmt) == SQLITE_ROW) { //46.3 
       NSInteger primaryKey = sqlite3_column_int(selectstmt, 0); 
       DataBaseClass *itemObj = [[DataBaseClass alloc] initWithPrimaryKey:primaryKey]; // 2.6% 

       itemObj.itemID = sqlite3_column_int(selectstmt, 0); 
       itemObj.itemName = ((char *)sqlite3_column_text(selectstmt,1)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)] : nil; 
       itemObj.availableIcon = ((char *)sqlite3_column_text(selectstmt,2)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)] : nil; 
       itemObj.notAvialableIcon = ((char *)sqlite3_column_text(selectstmt,3)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,3)] : nil; 
       itemObj.itemReleaseDate = ((char *)sqlite3_column_text(selectstmt, 4)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)] : nil; 
       itemObj.itemStatus = ((char *)sqlite3_column_text(selectstmt,5)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)] : nil; 
       itemObj.itemModDate = ((char *)sqlite3_column_text(selectstmt,6)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)] : nil; 
       itemObj.status_id = sqlite3_column_int(selectstmt, 7); 
       itemObj.availableLocalIconPath = ((char *)sqlite3_column_text(selectstmt,8)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 8)] : nil; 
       itemObj.notAvialableLocalIconPath = ((char *)sqlite3_column_text(selectstmt,9)) ? [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 9)] : nil; 

       [appDelegate.itemArray addObject:itemObj]; 
      } 
     } 
     sqlite3_finalize(selectstmt); 
    } 
    else 
     sqlite3_close(dataBase); //Even though the open call failed, close the database connection to release all the memory. 
} 

이 코드의 일부 줄에서 메모리 누수가 발생합니다. 이 문제를 어떻게 해결할 지 모르겠다. 내 응용 프로그램에서 ARC를 사용하고 있습니다. 그리고 좀비 모드에서 Xcode의 Instruments 도구를 사용하여 추적했습니다. 또한 일부 줄에서 누출 비율을 언급했습니다. 코드를 확인하고 도움을주십시오.

답변

0

성공하면 sqlite3_finalize가 호출되지만 데이터베이스를 닫지는 않습니다. 이 방법으로도 열면 여기도 닫아야합니다. 마지막 'else'를 제거하고 무슨 일이 일어나는 지보십시오.

+0

내가 말한대로 코드를 수정했지만 변경되지 않았습니다. – Mithuzz

관련 문제