Reputation: 2270
My project is ARC enabled. I have a class which is direct subclass of NSObject and my class has an NSArray(Strong reference). How can I release my array?
My understanding
In ARC no need of releasing objects
set nil to my NSArray(Strong reference) in dealloc method
- set nil to my NSArray(Strong reference) in viewDidUnload incase of view controller
This is the correct way of releasing my NSArray? If It's not then what is the correct approach?
Upvotes: 2
Views: 285
Reputation: 23634
So first of all, viewDidUnload
is no longer used so that is not an option. Second of all, you don't need to manually clear out instance variables of a class when it is deallocated unless they require some special cleanup. When an object is deallocated, it releases ownership of all of its instance variables so they will be deallocated automatically as long as nothing else is pointing to them with a strong reference. So the correct approach, as you asked, is to do nothing. The array will be deallocated on its own once your object is deallocated.
That said, if you really want to, you can clear out the pointer to the array like this:
myArray = nil;
This will then deallocate the array if there are no other strong references pointing to it which will in turn deallocate any elements in the array that have no other strong references pointing to them.
Upvotes: 5