문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top