在目标 c 中销毁不同类型对象的正确方法是什么? [英] what's the correct way destroy different kinds of objects in objective c?

查看:56
本文介绍了在目标 c 中销毁不同类型对象的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含对其他对象的引用的对象:

1) 意见
2)视图控制器
3)字典
4)数组
5)自定义对象.

摧毁它的最好方法是什么?我是否需要创建一个 destroy 方法来处理其不同属性的销毁?
这些类型中的每一种是否都有特殊的事情要做,或者我只是将它们全部设置为零?
注意:我正在使用 ARC.

谢谢,
宁录

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

推荐答案

这取决于你是否使用 自动引用计数 (ARC) 与否.

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

如果没有 ARC,您必须覆盖 dealloc 方法并释放您拥有的对象.

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

使用 ARC,您只需将主对象设置为 nil.ARC 将负责释放该对象以及它拥有的所有其他对象.

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.

这篇关于在目标 c 中销毁不同类型对象的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆