Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you release memory in xcode 4.2?

Tags:

xcode

In xcode 4.2 I have found it very frustrating because you can't use:

-(void)dealloc {
[label release]; //'release' is unavailable
[super dealloc]; //'dealloc' is forbidden in automatic reference counting
}

Is there another way because autorelease and other deallocs don't work either.

like image 658
iphonemaniac Avatar asked Oct 12 '11 02:10

iphonemaniac


2 Answers

Xcode 4.2 introduces "Automatic Reference Counting" (aka ARC). This is a compiler feature that basically inserts the retain and release calls for you. Under ARC, if you have a pointer to an object, you're retaining it. When your pointer goes out of scope, or is reassigned to point to another object, the original object is released. It's really nice.

So, in short, you just remove all the calls to retain, release, and autorelease, and the compiler will do the right thing for you.

like image 139
BJ Homer Avatar answered Sep 27 '22 00:09

BJ Homer


Read up on Automatic Reference Counting. If you write your code properly, you don't need to do any of that anymore.

If you want to use old code without converting, disable ARC. put -fno-objc-arc in the compiler flags for any source modules you don't want to use ARC.

joe

like image 35
Flyingdiver Avatar answered Sep 27 '22 00:09

Flyingdiver