나는 그것을 고치려고 몇 시간을 보냈지만 방금 포기했습니다. 나는 무엇이 잘못되었는지 전혀 모른다.iOS 메모리 문제의 Sqlite
내 응용 프로그램에서 내 모든 개체를 올바르게 설정하려면 중첩 된 SQL 작업을 수행합니다. 어떤 이유로 sqlite3 객체가 제대로 해제되지 않아 메모리가 지붕 위로 올라 가게됩니다. 올바르게 sql3_close 및 sql3_finalize를 사용하는 것이 문제라는 것을 알고 있습니다. 그러나 보시다시피, 나는 그들이 올바르게 사용했다고 생각합니다. 나는 정확히 같은 사용, 메모리를 엉망으로 사람에 따라서
- (IndoorLocation *) getIndoorLocationWithId:(NSNumber *) locId {
if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {
if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
//if I comment the thing below it works
NSNumber *_id = [[NSNumber alloc] initWithInt:(int) sqlite3_column_int(statement, 5)];
toReturn.outLoc = [self getOutdoorLocationWithId:_id];
[_id release];
}
sqlite3_finalize(statement);
}
sqlite3_close(db);
}
}
: 메모리를 엉망으로 한 그래서 여기
- (NSArray *) getAllSessions {
if (sqlite3_open(dbPath, &db) == SQLITE_OK) {
if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
//I found out that doing something like that
//toAdd.in_loc = [self getIndoorLocationWithId:[NSNumber numberWithInt:(int)sqlite3_column_int(statement, 6)]];
//messes the memory up all the time
//but doing that works OK:
NSNumber *_id = [[NSNumber alloc] initWithInt:(int) sqlite3_column_int(statement, 5)];
toAdd.out_loc = [self getOutdoorLocationWithId:_id];
[_id release];
//So I did the same with the second one, but this one messes memory up:
NSNumber *id2 = [[NSNumber alloc] initWithInt:(int)sqlite3_column_int(statement, 6)];
toAdd.in_loc = [self getIndoorLocationWithId:id2];
[id2 release];
}
sqlite3_finalize(statement);
}
sqlite3_close(db);
}
}
됩니다 : 여기
는 문제의 원인 함수가 처음으로 (getOutdoorLocationwithId) 같은 방식으로 작동하지만 작동하지 않으면 sqlite3 객체가 제대로 해제되지 않습니다.내 문제를 이해하시기 바랍니다.
데이터베이스가 이미 getAllSessions에서 열리고 다시 열리고 닫히면 데이터베이스가 엉망입니다. 두 가지 방법 모두에서 반환 유형을 선언하지만 아무 것도 반환하지 않습니다. xcode가이 문제에 대해 불평하지 않습니까? –
간단하게 유지하기 위해 모든 코드를 포함하지 않았습니다. 귀하의 첫 번째 요점에 관해서, 나는 동의하지만, 왜 그것이 처음이 아니라 두 번째가 작동합니까? – chopchop