Delegates - retain or assign - release?

前端 未结 3 979
别那么骄傲
别那么骄傲 2020-12-17 16:23

I\'ve seen a number of posts related to delegates, and I would like to know the proper way to reference them. Suppose I have an object declared like:

@inter         


        
3条回答
  •  没有蜡笔的小新
    2020-12-17 16:57

    I've heard a lot of opinions on this as well. I don't know the Right Way, but I can tell you what I've arrived at through my own work.

    You want to retain anything that you need to preserve your handle on. That's all ownership is, in a reference-counted environment. It's a declaration that "I'll need this later, don't let it go away on me".

    That ALSO means you're responsible for releasing your claim on it. If you don't specifically do that, you're prone to various problems, but especially dealing with delegates which might well retain the object they're a delegate of. If you don't deal with your retention of the delegate, the ownership will be cyclical and the objects will leak. But don't forget to release what you retain, and you'll be okay.

提交回复
热议问题