我正在尝试获取已保存到表格中的 Facebook 提要。从 Sqlite 表中检索数据后,我几乎没有内存泄漏。
我的代码是:-
-(void)viewWillAppear:(BOOL)animated
{
[self loadFBPostsfromDB];
}
//Calling function loadFBPostsfromDB
- (void) loadFBPostsfromDB{
//m_db = [[SQLHelper alloc] init];
if (fbPostArray!=nil) {
[fbPostArray release];
fbPostArray=nil;
}
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
SQLHelper *sqlHelper= [[SQLHelper alloc] init];
NSString *dbpath = [sqlHelper getDBPath];
[sqlHelper release];
sqlite3_stmt *selectStmt;
NSString *selectFBQuery=[NSString stringWithFormat:@"SELECT * from SocialFeeds where feedsSource='LondonFB'"];
NSLog(@"%@",selectFBQuery);
if(sqlite3_open([dbpath UTF8String], &database) == SQLITE_OK) {
const char *sql = [selectFBQuery UTF8String];
if(sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating select statement. '%s'",
sqlite3_errmsg(database));
self.fbPostArray=[[[NSMutableArray alloc] init] autorelease];
while(sqlite3_step(selectStmt) == SQLITE_ROW)
{
FaceBook *fb=[[FaceBook alloc] init];
fb.postTitle=[[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(selectStmt, 0)] autorelease];
fb.postdate=[[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(selectStmt, 1)] autorelease];
fb.link=[[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(selectStmt, 2)] autorelease];
[self.fbPostArray addObject:fb];
[fb release];
}
sqlite3_finalize(selectStmt);
}
[pool drain];
}
我附上仪器泄漏的屏幕截图