我是iphone的新手。我有一部分代码显示100%内存泄漏。为什么这会显示内存泄漏。我知道我已经释放了我的对象。 源代码:
Database_Methods *da=[[Database_Methods alloc] init];
self.newsArr=[da getNews:tableid];
[da release];
- (NSMutableArray *) getNews:(NSInteger )tableid {
NSString *tableName=[NSString stringWithFormat:@"Table%d",tableid];
NSMutableArray * categoryArray = [[NSMutableArray alloc] init];
@try {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString * docsDir = [paths objectAtIndex:0];
NSString * theDBPath = [docsDir stringByAppendingPathComponent: @"Training_Project2.sqlite"];
BOOL success = [fileManager fileExistsAtPath:theDBPath];
if (!success) {
NSLog(@"Failed to find database file '%@'.",theDBPath);
}
if (!(sqlite3_open([theDBPath UTF8String], &database) == SQLITE_OK)) {
NSLog(@"An error opening database, handle error here.");
}
NSString *query=[NSString stringWithFormat:@"SELECT link,flag,title FROM %@ order by rowid desc",tableName];
const char *sql = [query UTF8String];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) != SQLITE_OK) {
NSLog(@"Error, failed to prepare statement, handle error here.");
}
while (sqlite3_step(statement) == SQLITE_ROW) {
NewsRss * aCategory = [[NewsRss alloc] init];
//aCategory.categoryid = sqlite3_column_int(statement, 0);
aCategory.link = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
aCategory.flag = sqlite3_column_int(statement, 1);
aCategory.title=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
[categoryArray addObject:aCategory];
[aCategory release];
}