我正在使用 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);
}