データベースからすべてのデータを取得するために NSObject クラスを使用しています。その関数を呼び出すと、stringWithFormat を使用して文字列を割り当てるメモリ リークが表示されます。このメソッドを使用する場合、その文字列を解放する必要はないと思いますが、なぜメモリ リークが発生するのでしょうか?
前もって感謝します。:)
- (void) Allnote
{
[app.NoteArray removeAllObjects];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Notes.sqlite"];
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:@"SELECT * From note" ];
const char *sql = [querySQL UTF8String];
sqlite3_stmt *searchStatement;
if (sqlite3_prepare_v2(database, sql, -1, &searchStatement, NULL) == SQLITE_OK)
{
while (sqlite3_step(searchStatement) == SQLITE_ROW)
{
noteClass *noteObj = [[noteClass alloc]init];
noteObj.noteTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 0)]; // at this place
noteObj.noteContent = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 1)]; // at this place
NSNumber *noteId = [NSNumber numberWithInt:sqlite3_column_int(searchStatement, 2)];
noteObj.noteId = [NSString stringWithFormat:(@"%@"),noteId]; // at this place
files=noteObj.noteTitle;
filescont=noteObj.noteContent;
[app.NoteArray addObject:noteObj];
[noteObj release];
}
}
sqlite3_finalize(searchStatement);
}
sqlite3_close(database);
}