What happens if your brand of auto-advertisement as an abstract

My question may sound silly, but I like to know what happens if I mark an auto-implemented object as auto-advertising. Will he come out twice? Or is nothing happening? For instance:

Obj * obj = [[Obj create] autorelease]; 

Let's say [Obj create] returns an object with auto-implementation.
If I add another auto-advertisement, then what will happen?

+6
source share
2 answers

Yes, sending autorelease twice will release the object twice. If your create method returns an object with auto-implementation, and you send it an autorelease message, your application will fail because you will release the freed object.

Having said that, why don't you use the new Automatic Reference Counting (ARC) ? You no longer need to worry about the (automatic) release of objects.

+5
source

You use a class method (+), you do not have to care about memory. People use the class method. One of the reasons is that it can return an abstract object. If you release or auto-detect an object that returns a class method, it will crash.

-2
source

Source: https://habr.com/ru/post/925733/


All Articles