How can I fix this error: "ARC forbids explicit message send of 'release' in Xcode" [duplicate] How can I fix this error: "ARC forbids explicit message send of 'release' in Xcode" [duplicate] objective-c objective-c

How can I fix this error: "ARC forbids explicit message send of 'release' in Xcode" [duplicate]


Solution #1:

Just remove the release statement. ARC will manage it for you.

[imageArray release]; // remove this line

ARC is Auto Reference Counting. As opposite to manual reference counting.
There are a few great videos of talks from WWDC. I can provide the link if you wish to watch them.

In Transitioning to ARC Release Notes, see ARC Enforces New Rules:

You cannot explicitly invoke dealloc, or implement or invoke retain, release, retainCount, or autorelease.

The prohibition extends to using @selector(retain), @selector(release), and so on.

Solution #2:

If you do not wish to convert the code to ARC (e.g. you are not writing a new application, but are maintaining an old one / or you imported so much code that moving to ARC is not worth it) you can disable ARC.

  • Disabling ARC for selected files To disable ARC, you can use the -fno-objc-arc compiler flag for specific files. Select the targetand go to Build Phases -> Compile Sources. Edit the CompilerFlags and add -fno-objc-arc

  • Disabling ARC for the project
    Source:How to disable Xcode4.2 Automatic Reference Counting

    • Click on you project, in the left hand organizer.
    • Select your target, in the next column over.
    • Select the Build Settings tab at the top.
    • Scroll down to "Objective-C Automatic Reference Counting" (it may be listed as
    • "CLANG_ENABLE_OBJC_ARC" under the User-Defined settings group), and set it to NO.