what's the correct way destroy different kinds of objects in objective c?

隐身守侯 提交于 2019-12-10 17:10:17

问题


I have this object that contains references to other objects:

1)views
2)view controllers
3)dictionaries
4)arrays
5)custom objects.

what's the best way to destroy it? do I need to create a destroy method that will deal with the destruction of its different properties?
are there special things to be done in each one of these types or I just set them all to nil?
note: I am using ARC.

thanks,
Nimrod


回答1:


It depends on whether you use Automatic Reference Counting (ARC) or not.

Without ARC you have to override the dealloc method and release the objects you own.

With ARC you can just set your main object to nil. ARC will take care of releasing the object and all of the other objects it owns.




回答2:


As you are using ARC, You dont need to bother much about the releasing the objects, Unless there is some Retain Cycle.

You can send nil to your object as yourObject=nil; that will make it nil and will be released later on.



来源:https://stackoverflow.com/questions/14508134/whats-the-correct-way-destroy-different-kinds-of-objects-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!