GCD issue and too many threads

I have an image downloader class that is equipped with NSURL downloads and an image from the Internet and runs a completion block. The code is actually quite simple

- (void)downloadImageWithURL:(NSString *)URLString completion:(BELoadImageCompletionBlock)completion
{
    dispatch_async(_queue, ^{
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        UIImage *image = nil;
        NSURL *URL = [NSURL URLWithString:URLString];
        if (URL) {
            image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]];
        }  
        dispatch_async(dispatch_get_main_queue(), ^{
            completion(image, URLString);
        });
    });

}

When i replace

dispatch_async(_queue, ^{

with comments

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

, ( , , ). , , , 50 , downloadImageWithURL: : , _queue, , , 85+ . , dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0) 50 GCD ? , gcd , , , ?

+5
3

http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html

( ) , , . , , . , .

( ) , . ( ), .

[NSData dataWithContentsOfURL:URL]

, , GCD .

DISPATCH_QUEUE_PRIORITY_BACKGROUND. " ". , , .

, , NSOperation. NSBlockOperation, NSOperationQueue. NSOperationQueue - (NSInteger)maxConcurrentOperationCount, .

+2

, GCD ( , ).

, (, , ).

IO (, +[NSData dataWithContentsOfURL:] ), API, IO , . NSURLConnection - IO.

, . .

WWDC 2012 GCD .

+8

NSOperationqueue, NSURLConnection

:

- (void)setMaxConcurrentOperationCount:(NSInteger)count
+1

All Articles