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中的儀器工具在殭屍啓用模式下追蹤了這一點。而且我還提到了一些行中泄漏的百分比。請檢查代碼和幫助。
我修改了你所說的代碼,但沒有改變。 – Mithuzz