2012-04-10 30 views
0

我剛從ASIHTTP移動到AFNetworking庫。我還使用Olivier Poitrey和Peter Steinberg的SDURLCache庫。我想緩存我要在我的應用程序中使用的所有圖像。對於這些,我嘗試這樣做:IOS中的AFNetworking Cache圖像中的內存泄漏

NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
     for(NSURLRequest *imageRequest in imageRequestArray){ 
      AFURLConnectionOperation *operation2 = [[[AFURLConnectionOperation alloc] initWithRequest:imageRequest] autorelease]; 
      [queue addOperation: operation2]; 
      [operation2 waitUntilFinished]; 
} 

當我需要顯示的圖像,我這樣做對每個圖像:

NSURL *url = [NSURL URLWithString:[cat imagePath]]; 
     NSURLRequest *imageRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0]; 


     AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:imageRequest 
                        imageProcessingBlock:nil 
                          cacheName:@"nscache" 
                           success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){ 
                            //NSData *responseData = [request responseData]; 
                            imageView.alpha = 0.0; 
                            [imageView setImage:image forState:UIControlStateNormal]; 
                            [UIView beginAnimations:@"ToggleViews" context:nil]; 
                            [UIView setAnimationDuration:1.0];     
                            imageView.alpha = 1.0; 
                            [UIView commitAnimations]; 
                           } 
                           failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){} 
               ]; 
     [operation start]; 

一段時間後,應用程序使內存警告,然後關閉。爲此,我做了以下內容:

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { 
[[NSURLCache sharedURLCache] removeAllCachedResponses]; 
NSLog(@"Memory Warning..."); 
} 

它清除緩存(什麼,我也不是什麼),但一段時間後,再次申請關閉。

我該怎麼做?

+0

我相信我有類似的問題,當我用儀器檢查我的應用程序的內存使用量繼續上升,直到達到約200megs然後該應用程序由於內存警告而終止,我試圖追查問題,似乎沒有任何泄漏 – 2012-04-14 22:37:58

回答