Re: NSEvent isEqual
Re: NSEvent isEqual
- Subject: Re: NSEvent isEqual
- From: Matt Gough <email@hidden>
- Date: Wed, 3 May 2006 23:41:05 +0100
On 3 May 2006, at 23:24, John Stiles wrote:
If the pointer is the same, then by definition its contents must be
the same, right?
Yes and no. Consider this somewhat simple and contrived example:
static NSEvent* eventThatTriggeredUs;
void setup(NSEvent* anEvent)
{
eventThatTriggeredUs = anEvent;
}
void someTimeLater(NSEvent* anEvent)
{
if (eventThatTriggeredUs == anEvent)
{
// Must be the same event so we have to do our stuff
// Wrong - Without retaining in setup, anEvent might have been
released
// in the meantime and been replaced by an entirely new event at
the same address that is
// not supposed to cause us to end up in here.
}
}
You should always retain (eventThatTriggeredUs) in these cases to
avoid such pitfalls.
Matt Gough
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden