I’ve read that you should set delegate to nil in dealloc. I noticed it is doing it in init, is this ok or should you do the same in the dealloc?
“This is subtle one but handy one. If you’re passing yourself as a delegate to another object, reset that object’s delegate before you dealloc.”
file.h
@interface TestService : NSObject
{
NSObject <TestServiceDelegate> *m_delegate;
}
@property (nonatomic, assign) NSObject <TestServiceDelegate> *delegate;
file.m
@synthesize delegate=m_delegate;
- (id)init
{
if (self = [super init])
{
m_delegate = nil;
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
Neither one is needed.
In the case of the
initmethod, the instance variable will start innil, so it doesn’t matter.In the case of the
dealloc, as your delegate instance variable is (I’m guessing here, but if it’s not it should!) set as aweak(ARC) orassign(non-ARC) property, once you dealloc the object nothing will be sent to the delegate.