Ben Bauman
Ben Bauman

Reputation: 1087

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?

Upvotes: 3

Views: 652

Answers (2)

bbum
bbum

Reputation: 162722

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.

Upvotes: 7

Jeremy Roman
Jeremy Roman

Reputation: 16355

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

Upvotes: 2

Related Questions