0

以下のように、sqlite実行クエリコードがあります。Instruments は、NSDictionary の alloc および release 行 (while ループ内) でメモリ リークをキャッチします。誰かが alloc/release のどこが悪いのか指摘できますか?

- (NSMutableArray *)executeQuery:(NSString *)sql arguments:(NSArray *)args {
    sqlite3_stmt *sqlStmt;

    if (![self prepareSql:sql inStatament:(&sqlStmt)])
        return nil;

    int i = 0;
    int queryParamCount = sqlite3_bind_parameter_count(sqlStmt);
    while (i++ < queryParamCount)
        [self bindObject:[args objectAtIndex:(i - 1)] toColumn:i inStatament:sqlStmt];

    NSMutableArray *arrayList = [[NSMutableArray alloc]init]; // instrument marks leak 0.1 % on this line
    NSUInteger rcnt= arrayList.retainCount;
    int columnCount = sqlite3_column_count(sqlStmt);
    while ([self hasData:sqlStmt]) {
        NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];  // instrument marks leak 13% on this line
        for (i = 0; i < columnCount; ++i) {
            id columnName = [self columnName:sqlStmt columnIndex:i];
            id columnData = [self columnData:sqlStmt columnIndex:i];
            [dictionary setObject:columnData forKey:columnName];
        }
        [arrayList addObject:dictionary];
        [dictionary release];// instrument marks leak 86.9 % on this line
    }

    sqlite3_finalize(sqlStmt);
    rcnt=arrayList.retainCount;
    return arrayList ;
}

ヘルプ/ポインターは大歓迎です。数日間これに苦労しています。

4

1 に答える 1

0

ARC を使用していない場合は、戻り行を次のように変更することをお勧めします。

return [arrayList autorelease];

そうしないと、完全な arrayList がリークしている可能性があります。

于 2012-04-30T14:18:36.260 に答える