Should you set the delegate to nil in the class using the delegate or in the class itself

前端 未结 3 631
遥遥无期
遥遥无期 2020-12-16 15:44

If class A is using class B and class A is class B\'s delegate, is it ok if the delegate is set to nil in class B\'s dealloc? I have seen code usually resetting the delegate

3条回答
  •  我在风中等你
    2020-12-16 16:08

    As far as I know, its best practice to (assign) a delegate, such that you avoid circular references on retain counts for situations just like this. If you've set up the property properly, ie:

    @property (assign) id delegate;
    

    You shouldn't have to perform any memory management in the dealloc, as the retain count is not bumped when you call self.b.delegate = self; -- unlike using (retain) or (copy)

    Make sense? It would be fine to set the delegate to nil, but whats the point?

提交回复
热议问题