0

このループでメモリの問題が発生しました。私はARCを使用しているので、通常はオブジェクトを解放できません。しかし、このループプロセス中に、メモリが増大し、しばらくするとiPadがクラッシュします(警告やエラーなしで)。

この問題を解決するための解決策はありますか?なぜ記憶が大きくなるのか分かりませんか?

ご協力ありがとうございました。

_rawdatalocal = [NSEntityDescription insertNewObjectForEntityForName:@"RAWDATA"
                                                       inManagedObjectContext:managedObjectContext];    

for(int j = 1; j <[array count];j++)
        {
            NSArray *values = [[NSArray alloc] initWithArray:[[array objectAtIndex:j] componentsSeparatedByString:@";"]];

            if([values count] == 12)
            {
            _rawdatalocal.accX = [[NSNumber alloc] initWithInt:[[values objectAtIndex:1] intValue]];
                _rawdatalocal.accY = [[NSNumber alloc] initWithInt:[[values objectAtIndex:2] intValue]];
                _rawdatalocal.accZ = [[NSNumber alloc] initWithInt:[[values objectAtIndex:3] intValue]];
                _rawdatalocal.gyrX = [[NSNumber alloc] initWithInt:[[values objectAtIndex:4] intValue]];
                _rawdatalocal.gyrY = [[NSNumber alloc] initWithInt:[[values objectAtIndex:5] intValue]];
                _rawdatalocal.gyrZ = [[NSNumber alloc] initWithInt:[[values objectAtIndex:6] intValue]];
                _rawdatalocal.magX = [[NSNumber alloc] initWithInt:[[values objectAtIndex:7] intValue]];
                _rawdatalocal.magY = [[NSNumber alloc] initWithInt:[[values objectAtIndex:8] intValue]];
                _rawdatalocal.magZ = [[NSNumber alloc] initWithInt:[[values objectAtIndex:9] intValue]];
                _rawdatalocal.temperature = [[NSNumber alloc] initWithFloat:[[values objectAtIndex:10] floatValue]];
                _rawdatalocal.temps = [[NSNumber alloc] initWithInt:[[values objectAtIndex:11] intValue]];

        }

PS:通常、以下の行はループ内にあります

_rawdatalocal = [NSEntityDescription insertNewObjectForEntityForName:@"RAWDATA"
                                                           inManagedObjectContext:managedObjectContext];
4

1 に答える 1

1

ループ内に自動解放プールを配置して、メモリの急増を回避できます。アークでは、自動リリースのポーリングを次のように配置する必要があります。

@autorelease{

}

詳細はこちら

于 2013-02-25T17:56:22.673 に答える