When I created my project, I checked the "Use Automatic Reference Counting" to on. Now, I'm thinking of turning it off but I can't find where to change it.
One more thing, is it advisable to use ARC for iPad/iPhone apps?
Open the project file.
Under Build Settings tab search for "Objective-C Automatic Reference Counting".
Set the value for it.
Yes, sure if you want to deliver a product for iOS 4.0 and above you can definitely use ARC.
You can turn off "Use Automatic Reference Counting" by clicking on your project in the navigator (the top item in the finder-like thing on the left) click on your target, select "Build Settings" and turn off the option "Objective-C Automatic Reference Counting"
If programmer is novice than it is good advice to let them do it manually , otherwise his memory fundamentals will be never clear , Otherwise it is just fine to use it.
Go to the Project Menu->Target->Build Settings->Objective-C Automatic Reference Counting, then you can set here Yes or No. if You are a beginner and You can't handle memory issue yourself then you can enable ARC.
Related
I am new to iOS development. When I created my project, I chose the wrong setting for ARC, and now I don't know how to go back and change that setting. Where can I find that?
You have to go under the section Build settings of the project settings and change the value of the : Objective-C Automatic Reference Counting property :
Go into the Build Settings and search for "automatic reference counting" and you should see a Yes/No option.
I want to bring a single Objective-C class written using ARC into an old project. The internet provides many references for how to enable ARC for your project and then disable it for single files but I want to do the opposite.
I want to leave the project as it is, i.e. using manual reference counting, and then enable ARC just for the new file. (My searches have failed me here.)
Is this possible? How?
Add the -fobjc-arc flag to any files for which you'd like to enable ARC, as described in the ARC documentation.
Select Target > Build Phases > Compile Source > Select Your class > Double Click> Type
-fobjc-arc in dialog box
Enter.
If a project has already been created with ARC disabled, how do I enable it and vice versa?
Open your project and select Edit -> Refactor -> Convert to Objective-C ARC.
This will start checking your code if it is ready for the conversion.
See also Clang documentation: Objective-C Automatic Reference Counting (ARC)
How to disable ARC has been answered here
Following are the steps which I did and it worked for me
Select Project
Select Targets
From the right panel, select Build Settings
Search for "Automatic Reference Counting";
Locate Apple LLVM compiler 3.0 - Language and Objective-C Automatic Reference Counting and select NO in all three sections.
When you migrate a project to use ARC, the -fobjc-arc compiler flag is set as the default for all Objective-C source files. You can disable ARC for a specific class using the -fno-objc-arc compiler flag for that class. In Xcode, in the target Build Phases tab, open the Compile Sources group to reveal the source file list. Double-click the file for which you want to set the flag, enter -fno-objc-arc in the pop-up panel, then click Done.
In Xcode 5.0.2, select your project in Navigatior, select Build Settings, search for Apple LLVM 5.0 - Language - Objective C and change Objective-C Automatic Refence Counting to NO
How do I set up NSZombieEnabled and CFZombieLevel for my executable in Xcode 4?
In Xcode 4.x press
⌥⌘R
(or click Menubar > Product > Scheme > Edit Scheme)
select the "Diagnostics" tab and click "Enable Zombie Objects":
This turns released objects into NSZombie instances that print console warnings when used again. This is a debugging aid that increases memory use (no object is really released) but improves error reporting.
A typical case is when you over-release an object and you don't know which one:
With zombies: -[UITableView release]: message sent to deallocated instance
Without zombies:
This Xcode setting is ignored when you archive the application for App Store submission. You don't need to touch anything before releasing your application.
Pressing ⌥⌘R is the same as selecting Product > Run while keeping the Alt key pressed.
Clicking the "Enable Zombie Objects" checkbox is the same as manually adding "NSZombieEnabled = YES" in the section "Environment Variables" of the tab Arguments.
Jano's answer is the easiest way to find it.. another way would be if you click on the scheme drop down bar -> edit scheme -> arguments tab and then add NSZombieEnabled in the Environment Variables column and YES in the value column...
I find this alternative more convenient:
Click the "Run Button Dropdown"
From the list choose Profile
The program "Instruments" should open where you can also choose Zombies
Now you can interact with your app and try to cause the error
As soon as the error happens you should get a hint on when your object was released and therefore deallocated.
As soon as a zombie is detected you then get a neat "Zombie Stack" that shows you when the object in question was allocated and where it was retained or released:
Event Type RefCt Responsible Caller
Malloc 1 -[MyViewController loadData:]
Retain 2 -[MyDataManager initWithBaseURL:]
Release 1 -[MyDataManager initWithBaseURL:]
Release 0 -[MyViewController loadData:]
Zombie -1 -[MyService prepareURLReuqest]
Advantages compared to using the diagnostic tab of the Xcode Schemes:
If you forget to uncheck the option in the diagnostic tab there no objects will be released from memory.
You get a more detailed stack that shows you in what methods your corrupt object was allocated / released or retained.
In Xcode 4.2
Project Name/Edit Scheme/Diagnostics/
Enable Zombie Objects check box
You're done
On In Xcode 7
⌘<
or select Edit Scheme from Product > Scheme Menu
select Enable Zombie Objects form the Diagnostics tab
As alternative, if you prefer .xcconfig files you can read this article https://therealbnut.wordpress.com/2012/01/01/setting-xcode-4-0-environment-variables-from-a-script/
Cocoa offers a cool feature which greatly enhances your capabilities to debug such situations. It is an environment variable which is called NSZombieEnabled, watch this video that explains setting up NSZombieEnabled in objective-C
In Xcode > 4.3:
You click on the scheme drop down bar -> edit scheme -> arguments tab and then add NSZombieEnabled in the Environment Variables column and YES in the value column.
Good Luck !!!
I have an app that is crashing with no error tracing. I can see part of what is going on if I debug, but can't figure out which object is "zombie-ing".
Does anybody know how to enable NSZombie in Xcode 4?
Environment variables are now part of the "scheme".
To edit the scheme and turn on zombies:
In the "Product" menu, select "Scheme" > "Edit Scheme...".
Go to the "Run Foo.app" stage in the left panel, and the "Arguments" tab on the right.
Add NSZombieEnabled to the "Environment Variables" section and set the value to YES, as you could in Xcode 3.
In Xcode 4.1 and above, there's also a checkbox on the "Diagnostics" tab of the "Run" stage to "Enable Zombie Objects".
With Xcode 6.4:
I encountered the same problem with troubleshooting EXC_BAD_ACCESS and had hard time to find the setting with Xcode 4.2 (the latest one that comes with iOS5 SDK). Apple keeps on moving things and the settings are no longer where they used to be.
Fortunately, I've found it and it works for the device, not just Simulator. You need to open the Product menu in the Xcode, select Edit scheme and then choose the Diagnostics tab. There you have "Enable Zombie Objects". Once selected and run in debugger will point you to the double released object! Enjoy!
In short
Product->Edit Scheme->Diagnostics-> Click Enable Zombie Objects
Product > Profile will launch Instruments and then you there should be a "Trace Template" named "Zombies". However this trace template is only available if the current build destination is the simulator - it will not be available if you have the destination set to your iOS device.
Also another thing to note is that there is no actual Zombies instrument in the instrument library. The zombies trace template actually consists of the Allocations instrument with the "Enable NSZombie detection" launch configuration set.
It's a simple matter of setting an environment variable on your executable (NSZombieEnabled = YES), and then running/debugging your app as normal.If you message a zombie, your app will crash/break to debugger and NSLog a message for you.
For more information, check out this CocoaDev page: http://www.cocoadev.com/index.pl?NSZombieEnabled
Also, this process will become much easier with the release of 10.6 and the next versions of Xcode and Instruments. Just saying'. =)
Product > Profile will pop up Instruments. Select zombies from the panel and go nuts.
Go to Product - Scheme - edit scheme - Arguments - Environment Variables set NSZombieEnabled = YES
In xcode 4.2
Goto, Product -> edit scheme -> click Run yourappname.app -> Diagonostics -> Enable Zombie object.
Here's a video and explaination how to use Instruments and NSZombie to find and fix memory crashes on iOS:
http://www.markj.net/iphone-memory-debug-nszombie/
As of Xcode 3.2.5 and Snow Leopard (Mac OS X 10.6), you can run your code through the Zombies instrument: Run > Run with Performance Tool > Zombies. That allows you to see particular objects and their retain counts on a timeline.
In Xcode 4.5.2 goto Product -> Edit Scheme -> and Under the Diagnostics tab check the check box in between Objective C and Enable Zombie Objects and Click on OK
To enable Zombie logging double-click the executable in the executables group of your Xcode project. At this point click the Arguments tab and in the Variables to be set in the environment: section, make a variable called NSZombieEnabled and set its value to YES.
In XCode 4.0: To detect NSZombie in Instruments, select the Simulator as your target (can't detect NSZomboe on device). Run Instruments (CMD+I) and select "Zombies" trace template. Enjoy.
In the preferences of your executable add the environment variable NSZombieEnabled and set the value to YES.
in ur XCODE (4.3) next the play button :) (run)
select : edit scheme
the scheme management window will open
click on the Arguments tab
you should see : 1- Arguments passed on launch
2- environment variables
inside the the (2- environment variables) place
Name: NSZombieEnabled
Value: YES
And its done....
NSZombieEnabled is used for Debugging BAD_ACCESS,
enable the NSZombiesEnabled environment variable from Xcode’s schemes sheet.
Click on Product⇒Edit Scheme to open the sheet and set the Enable Zombie Objects check box
this video will help you to see what i'm trying to say.