SQLite中的iPhone内存泄漏问题选择查询

时间:2012-07-04 19:11:21

标签: iphone sqlite memory-leaks nsmutablearray

我正在尝试将已保存到桌面的Facebook Feed。从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];
}

我附上了仪器泄漏的截图 Leak Image

0 个答案:

没有答案
相关问题