Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 376
Nimrod Yizhar Avatar asked Feb 18 '23 18:02

Nimrod Yizhar


2 Answers

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.

like image 188
DrummerB Avatar answered May 16 '23 06:05

DrummerB


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.

like image 37
Anoop Vaidya Avatar answered May 16 '23 08:05

Anoop Vaidya