在objective - c中,正确的销毁不同类型物体的方法是什么?

时间:2021-06-25 13:30:18

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)视图2)视图控制器3)字典4)数组5)自定义对象。摧毁它的最好方法是什么?我需要创建一个销毁方法来处理其不同属性的破坏吗?在每种类型中都有特殊的事情要做吗?或者我把它们都设为nil?注意:我使用的是ARC。谢谢,猎人

2 个解决方案

#1


6  

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

这取决于您是否使用自动引用计数(ARC)。

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

没有ARC,您必须重写dealloc方法并释放您所拥有的对象。

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.

使用ARC你可以将你的主对象设置为nil。ARC将负责释放对象和它所拥有的所有其他对象。

#2


1  

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

当您使用ARC时,您不需要为释放对象而费心,除非有一些保留循环。

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

你可以将nil发送给你的对象,正如yourObject=nil;这将使它为nil,并将在稍后发布。

#1


6  

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

这取决于您是否使用自动引用计数(ARC)。

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

没有ARC,您必须重写dealloc方法并释放您所拥有的对象。

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.

使用ARC你可以将你的主对象设置为nil。ARC将负责释放对象和它所拥有的所有其他对象。

#2


1  

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

当您使用ARC时,您不需要为释放对象而费心,除非有一些保留循环。

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

你可以将nil发送给你的对象,正如yourObject=nil;这将使它为nil,并将在稍后发布。