从sqlite获取数据时内存泄漏

时间:2012-01-04 14:53:29

标签: iphone ios sqlite

我编写了一个fetchAllFromDatabase来从我的数据库中获取数据。 守则是:

if ([tableName isEqualToString:kFavouriteStoresList]) {
                    NSMutableDictionary *dictFavStoreDetails = [[NSMutableDictionary alloc] init];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,0)] forKey:kFavouriteStoresList_ZipCode];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,1)] forKey:kFavouriteStoresList_StoreNumber]; // Leaking Memory
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,2)] forKey:kFavouriteStoresList_Address]; // memory leak
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,3)] forKey:kFavouriteStoresList_StoreName];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,4)] forKey:kFavouriteStoresList_City];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,5)] forKey:kFavouriteStoresList_State];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,6)] forKey:kFavouriteStoresList_Phone]; // Memory leak
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,7)] forKey:kFavouriteStoresList_Latitude];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,8)] forKey:kFavouriteStoresList_Longitude];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,9)] forKey:kFavouriteStoresList_sHrsMonToThu];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,10)] forKey:kFavouriteStoresList_sHrsFri];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,11)] forKey:kFavouriteStoresList_sHrsSat];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,12)] forKey:kFavouriteStoresList_sHrsSun];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,13)] forKey:kFavouriteStoresList_pHrsMonToThu];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,14)] forKey:kFavouriteStoresList_pHrsFri];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,15)] forKey:kFavouriteStoresList_pHrsSat];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,16)] forKey:kFavouriteStoresList_pHrsSun];
                    [dictFavStoreDetails setObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement,17)] forKey:kFavouriteStoresList_StoreServicesList];

                    [tempFetchArray addObject:dictFavStoreDetails];
                    [dictFavStoreDetails release];
                    dictFavStoreDetails = nil;
                }

在这里,我收到3行内存泄漏(参见3行内存泄漏评论)。任何人都可以告诉我为什么会这样吗

1 个答案:

答案 0 :(得分:0)

您使用静态分析仪吗?如果案例仔细查看消息,有时泄漏不会放在正确的行上。