有人可以幫我解釋爲什麼這段代碼在泄漏,我們該如何處理它?iphone:奇怪的漏洞
sqlite3 *database;
if (pickerList) {
self.pickerList=nil;
[pickerList release];
}
self.pickerList=[[NSMutableArray alloc] init];
NSString *dbPath = [self applicationDocumentsDirectory];
dbPath=[dbPath stringByAppendingPathComponent:@"database"];
dbPath=[dbPath stringByAppendingPathComponent:@"OFFENDERSDB.sqlite"];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
if (isAlertForViolationPicker) {
const char *sqlStatement = "SELECT * FROM VIOLATIONS_TBL";
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while (sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *recSTR=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
[self.pickerList addObject:recSTR];
[recSTR release];
recSTR=nil;
}
}
//[tempRowArray release];
sqlite3_finalize(compiledStatement);
//sqlite3_reset(compiledStatement);
sqlite3_close(database);
}
else {
const char *sqlStatement = "SELECT * FROM PLAN_TBL";
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while (sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *recSTR=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
[self.pickerList addObject:recSTR];
[recSTR release];
recSTR=nil;
}
}
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
}
}
sqlite3_reset(compiledStatement);
recSTR在這種情況下漏水,我已經嘗試了所有下面提到的解決方案,但沒有工作(更新代碼) Thanx提前
你不會在這裏泄漏'recSTR'。漏洞很可能與該字符串涉及'pickerList'有關。這個代碼是不夠的,以弄清楚。 – 2011-06-04 18:53:25
Double post:http://stackoverflow.com/questions/6235632/iphone-memory-leak-while-reading-data-in-loop-from-datatbase – dasdom 2011-06-04 18:56:28
儀器只告訴你泄漏對象的創建位置,而不是它在哪裏被泄露。 – albertamg 2011-06-04 19:04:25