Checking if an object has been released before sending a message to it
Posted
by Tom Irving
on Stack Overflow
See other posts from Stack Overflow
or by Tom Irving
Published on 2010-06-02T00:28:15Z
Indexed on
2010/06/02
0:33 UTC
Read the original article
Hit count: 253
I've only recently noticed a crash in one of my apps when an object tried to message its delegate and the delegate had already been released.
At the moment, just before calling any delegate methods, I run this check:
if (delegate && [delegate respondsToSelector:...]){
[delegate ...];
}
But obviously this doesn't account for if the delegate isn't nil, but has been deallocated.
Besides setting the object's delegate to nil in the delegate's dealloc
method, is there a way to check if the delegate has already been released just incase I no longer have a reference to the object.
© Stack Overflow or respective owner