Have you checked that you have initialized the "timer" pointer to nil? Like C, in Objective-C local variables (as opposed to instance variables) are allocated on the stack frame and have unspecified initial values. About the only thing you can count on for sure is that the initial value is NOT nil (i.e. 0x0).

So, if your code is structured like the below snippet, then I would expect BAD_ACCESS every time. That's because the first check is TRUE (timer indeed is not nil), and the second check has the side effect of attempting to invoke the isValid method at a memory location that is 1) random, and 2) certainly not even an Obj-C object. The BAD ACCESS would result from the Obj-C runtime attempting to dereference the timer pointer out to no-man's memory land.

Instance variables and static variables are initialized to bitwise 0's, so the above analysis would not apply in that case.

Just some thoughts.

-S

-(void)aMethod
{
   NSTimer *timer;
 if(timer!=nil && [timer isValid]) [timer invalidate];
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to