Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARC - why do object pointers require explicit ownership type in function definitions?

void testFunction (id testArgument[]) {
    return;
}

I'm getting the error "Must explicitly describe intended ownership of an object array parameter". Why does ARC need me to specify the ownership type of the objects in the testArgument array?

like image 626
Binyamin Bauman Avatar asked Nov 23 '25 07:11

Binyamin Bauman


2 Answers

To expand on Jeremy's answer, ARC had two primary goals when designed:

  • make memory management as fully automatic as possible in pure Objective-C code while also preserving or maximizing efficiency (in fact, ARC can be more efficient than manual retain release).

  • require exactly specific declaration of memory management intent when crossing the boundary between C and Objective-C.

As well, the implementation of ARC is extremely conservative. That is, anywhere where the behavior has traditionally been "undefined", ARC will spew a warning.

Thus, in this case, the declaration of intent is required so that the compiler can apply a consistent and specific set of memory management rules to the contents of the array.

like image 131
bbum Avatar answered Nov 24 '25 23:11

bbum


Because ARC needs to know whether to insert retain/release calls for you to avoid memory leaks.

like image 21
Jeremy Roman Avatar answered Nov 24 '25 22:11

Jeremy Roman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!