小编Ric*_*nes的帖子

内存泄漏在循环中使用dataWithContentsOfURL

我正在使用Xcode 4.6.3和iOS 5.5/6.1.6.

我正在使用后台线程从服务器向iOS设备加载大量的jpg.

dispatch_async(kBgQueue, ^
               {
                   // get the array of filenames to download
                   NSURL* url = [NSURL URLWithString:webPath];
                   NSArray* theArray = [NSArray arrayWithContentsOfURL:url];
                   if( theArray )
                   {
                       dispatch_async(dispatch_get_main_queue(), ^{
                           // disable screen buttons
                           [self setButtons:false];
                       });

                       [self loadImagesFromList:theArray sourceBundle:bundlePath destBundle:localBundlePath manager:manager];

                       if (!stopFlag) {
                           // if no memory error has occurred
                           NSLog(@"calling refresh after load_images");
                           dispatch_async(dispatch_get_main_queue(), ^{
                               [self refresh];
                           });
                       }
                       theArray = nil;
                   }
                   else
                   {
                       NSLog(@"Error loading bundle");
                   }
               });
Run Code Online (Sandbox Code Playgroud)

背景方法:

-(void)loadImagesFromList:(NSArray *)theArray
             sourceBundle:(NSString *)bundlePath
               destBundle:(NSString …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch memory-leaks block objective-c ios

2
推荐指数
1
解决办法
970
查看次数

标签 统计

block ×1

cocoa-touch ×1

ios ×1

memory-leaks ×1

objective-c ×1