Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to release GCD queues under ARC in iOS 6.0?

Tags:

Following an iOS 5 tutorial on the Paul Hegarty course we see this code in an app that demonstrates use of GCD. Apparently GCD requires release because of issues to do with multithreading being somewhat unpredictable in what objects are still needed.

  dispatch_async(dowloadQueue, ^{
    ....
    // do some stuff
   ....
    });
  dispatch_release(dowloadQueue);

I have upgraded to iOS 6 and XCode 4.5 and I get an "ARC forbids explicit release ..." message

I did not try this code under iOS5 / XCode 4.2

Is this just because ARC got more clever and I no longer need release in GCD? Or have I just misunderstood?

like image 346
nerak99 Avatar asked Oct 04 '12 15:10

nerak99


1 Answers

When you target Mountain Lion and iOS 6.0, ARC will now manage dispatch queues and other GCD types for you. If you target earlier versions of OS X or iOS, you will still need to explicitly retain and release GCD types (not just for thread safety reasons, you'll leak memory otherwise), but this is handled for you when only targeting the newer OS versions.

This is why you see such a compiler error under ARC when targeting iOS 6.0.

like image 139
Brad Larson Avatar answered Nov 18 '22 15:11

Brad Larson