[英]Memory leak on iPhone
嗨,我是用泄漏工具找到泄漏的,但不知道為什么這種方法會導致泄漏。 有什么幫助嗎? 代碼在下面
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
NSString *str = [NSString stringWithFormat:@"SELECT UsageData.Date,UsageData.Time,UsageData.NoOfMovementRegistered,UsageData.BreathingRate,UsageData.TimeSinceLastMovement,UsageData.Status,UsageData.bID FROM UsageData INNER JOIN Beds ON UsageData.bID = Beds.bID WHERE Status = 'Alert' OR Status = 'Unused' GROUP BY UsageData.bID ORDER BY UsageData.bID LIMIT '%d'",[appDelegate.beds count]];
const char *sqlStatement = [str UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement,-1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
//leak NSString *aDate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)] ;
//leak NSString *aTime = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] ;
//leak NSString *aNoOfMoveReg = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] ;
//leak NSString *aBreathRate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] ;
//leak NSString *aTimeSinceLastMovement = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)] ;
//leak NSString *aStatus = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)] ;
//leak NSString *aBID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)] ;
NSLog(@"aDate %@",aDate);
NSLog(@"aTime %@",aTime);
NSLog(@"aNoOfMoveReg %@",aNoOfMoveReg);
NSLog(@"aBreathRate %@",aBreathRate);
NSLog(@"aTimeSinceLastMovement %@",aTimeSinceLastMovement);
NSLog(@"aStatus %@",aStatus);
NSLog(@"aBID %@",aBID);
IconUsageData *usagedata = [[IconUsageData alloc] initWithDate:aDate time:aTime noofmovereg:aNoOfMoveReg breathrate:aBreathRate timesincelastmovement:aTimeSinceLastMovement status:aStatus bedid:aBID];
[appDelegate.iconUsageDatas addObject:usagedata];
[usagedata release];
[aDate release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
*編輯以顯示上面的屏幕截圖
解決了,在上述代碼范圍之外的變量中,有一個未被釋放。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.