Understanding when to call retain on an object?

前端 未结 4 537
礼貌的吻别
礼貌的吻别 2021-01-12 21:01

When should retain be used ? I understand that it increments the object references count, so basicly the next release on that object will not call

4条回答
  •  [愿得一人]
    2021-01-12 21:54

    I usually just use retain explicitly when there is a need to and the Xcode debugger tells me what just happened when such a situation arises. Usually for whatever reason (mismanagement on the developer's part or if there is some release going on behind the scenes), you do anything on a released object, you'd get a crash. Just read the log on the console, see the debugger on Xcode when you debug and you figure out usually which object is causing the problem.

提交回复
热议问题