Re: NSTimer EXC_BAD_ACCESS
Re: NSTimer EXC_BAD_ACCESS
- Subject: Re: NSTimer EXC_BAD_ACCESS
- From: Jens Bauer <email@hidden>
- Date: Sun, 14 Dec 2008 20:52:55 +0100
That's an easy one. -Easy for me, because I had much trouble with it
earlier. =)
Remember to retain your timer:
- (void)timerStop
{
if(timer)
{
[timer invalidate];
[timer release];
timer = NULL;
}
}
- (void)timerStart:(double)aSecondInterval
{
[self timerStop];
timer = [[NSTimer scheduledTimerWithTimeInterval:aSecondInterval
target:self selector:@selector(_updateDisplay:) userInfo:NULL
repeats:YES] retain];
}
...and make timer a member variable of your class.
You probably experience your crash, because the timer is autoreleased.
If you retain it, it'll live. However, you'll have to remember the
timer object, so you can stop it later, so add NSTimer *timer; as a
member variable of your class...
- (void)dealloc
{
[self timerStop];
[super dealloc];
}
Love,
Jens
On Dec 14, 2008, at 06:07, Daniel Luis dos Santos wrote:
Hello,
I have a NSTimer that is created every time I press a button. It
then calls the update function successively until some amount of
time passes.
When I press the button again I get a EXC_BAD_ACCESS on the timer's
initialization :
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: step
target: self
selector: @selector(_updateDisplay:) userInfo: nil repeats: YES];
step is a double, and _updateDisplay has the right signature.
The stack trace is something like :
#0 0x90705558 in tiny_malloc_from_free_list
#1 0x906fe3ed in szone_malloc
#2 0x906fe2f8 in malloc_zone_malloc
#3 0x932b9451 in _CFRuntimeCreateInstance
#4 0x9327f844 in CFDateCreate
#5 0x93329f63 in -[__NSPlaceholderDate
initWithTimeIntervalSinceReferenceDate:]
#6 0x9332a7fd in +[NSDate dateWithTimeIntervalSinceNow:]
#7 0x9034aa3f in +[NSTimer(NSTimer)
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:]
I haven't any idea,...
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden