Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARC equivalent of autorelease?

If I have this code,

+ (MyCustomClass*) myCustomClass
{
    return [[[MyCustomClass alloc] init] autorelease];
}

This code guarantees the returning object is autoreleased. What's the equivalent of this in ARC?

like image 567
eonil Avatar asked Nov 28 '11 06:11

eonil


2 Answers

There is no equivalent in ARC, as you don't need to do it yourself. it will happen behind the scenes and you are not allowed to do it your self.

You simply use -

+ (MyCustomClass*) myCustomClass
{
    return [[MyCustomClass alloc] init];
}

I suggest you to watch the ARC introduction in the 2011 WWDC as it very simple when you get it.

Look here: https://developer.apple.com/videos/wwdc/2011/

And as the guy in the movie says -

You don't have to think about it any more (almost)

like image 125
shannoga Avatar answered Oct 29 '22 03:10

shannoga


When compiling with ARC, you simply write it as:

+ (MyCustomClass *)myCustomClass
{
    return [[MyCustomClass alloc] init];
}

and the compiler/runtime will handle the rest for you.

like image 7
justin Avatar answered Oct 29 '22 03:10

justin