On Feb 25, 2014, at 10:53 , Jeff Evans <email@hidden> wrote:
I'm interested in knowing what the flaw is.
It’s a little bit subtle, because the power of suggestion hides a really simple flaw:
if (_weakIVar) [_weakIVar someMessage];
The flaw is that _weakIVar can become nil *after* the if-test and *before* the message send. You could be sending a message to nil in spite of the if-test. In other words, the if-test does precisely nothing.
The power of suggestion comes into it because, when you read the if-test, you tend to believe it does what it appears to do.
The flaw is harmless in this simple example, but in a more complicated sequence:
if (_weakIVar) { … [_weakIVar salvageAllHumanKnowledge]; [self destroyThePlanet]; }
the outcome might not be what you intended.
|