0

これは私のコードであり、メモリを解放せず、60 mb に達し、アプリケーションが強制終了します

for (int i=0; i<[modelList カウント] ;i++) {

    url=@"http://192.168.0.101/images/projectimages/";
    url=[url stringByAppendingString:[modelList objectAtIndex:i]];
    url=[url stringByAppendingString:@".jpg"];


    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];




    NSData *imageData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];

    destinationPath=[documentsDirectory stringByAppendingString:@"/modelimages"];
    destinationPath=[destinationPath stringByAppendingPathComponent:[modelList objectAtIndex:i]];
    destinationPath=[destinationPath stringByAppendingString:@".jpg"];

    [imageData writeToFile:destinationPath atomically:YES];

    [imageData release];
    //imageData=nil;
    //[myurl release];  

    //[imageData release];  

    value=value+divideValue;
    printf("%f\n",value);
    [NSThread detachNewThreadSelector:@selector(updateProgressBar)toTarget:self withObject:nil];

}
4

1 に答える 1

2

これはひどいです:

[NSThread detachNewThreadSelector:@selector(updateProgressBar)toTarget:self withObject:nil];

それは:

  1. 多くのスレッドを作成します。
  2. メインスレッドからのみ更新する必要がありますが、UI を更新することを期待しています。

私はそのようなことをする方がはるかに良いと思います:

[self performSelectorOnMainThread:@selector(updateProgressBar) 
                       withObject:nil // or any object you need to pass
                    waitUntilDone:NO] //

そして、あなたが例として示した方法 - 代わりに別のスレッドで実行する必要があります。この場合、1 つのバックグラウンド スレッドがすべてのハードワークを実行し、ユーザー インターフェイスの更新についてメイン スレッドに通知します。

于 2009-09-01T13:46:50.657 に答える