When a custom class is created in Objective C, when and how is the dealloc
method called? Is it something that I have to implement somehow in my class?
Imagine that -release
is implemented in NSObject like this:
- (void)release
{
_retainCount--;
if (_retainCount == 0) {
[self dealloc]
}
}
I'm sure it's a little more complicated than that, but the answer to your question is that the object itself will call -dealloc
when its retain count drops to zero. However, your custom class will inherit this behavior from NSObject. You'll never need to call -dealloc yourself in code that you write; it'll always happen automatically when the object has been properly released.