Domanda

I wonder how memory management must be done for method parameters that are used to pass values into the method and (optionally) return updated values from the method.

For example, the -validate<Key>:error: method in KVC has a (id *)ioValue parameter that can be updated by the method. You can return an autoreleased object but what should you do with the input object when updating? Are there any conventions for this case?

È stato utile?

Soluzione

There isn't anything particularly complex about replacing an object reference with a new object, just as taking a nil reference and making it valid when an object is first created.

If you are using ARC then the compiler will realise that the old reference has been replaced, just like it would in any other situation. If using MRR then you are required to observe the normal retain/release conventions in order to avoid a memory leak.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top