Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: NSTimer: Target object missing when timer fires?




Subject: NSTimer: Target object missing when timer fires?

Hi,

I have the following code in my application. It is called off of awakeFromNIB().
This is to set up a timer and so for the application to be called again at a certain time.


{
NSTimer* nextUpdateTimer =
[[NSTimer alloc] initWithFireDate: (NSDate*)nextDueDate
interval:(NSTimeInterval) PTUpdateInterval
target: self
selector: @selector(respondTimeout:)
userInfo: nil
repeats: YES];

[[NSRunLoop currentRunLoop] addTimer:nextUpdateTimer forMode:NSDefaultRunLoopMode];
[nextUpdateTimer release];
}


The timer works, however there is a problem because the memory accessed in the callback looks to be invalid.
In the respondTimeout method the self object appears in the top right pane. The same memory address are printed up by the debugger for the self object as before when in the awakeFromNIB. However the contents of the memory are invalid or do not correspond to the original object that set the timer, and to which the selector function belongs. Its as if the target object has been moved about in its memory space or that the memory space is changed. The selector method then calls another method belonging to the object and that works. However when the method tries to access the class data then a bad access occurs.


At first I thought it was something to do with NSApplication because I originally subclassed NSApplication. But when I changed my implementation into a delegate and the problem still persists. Ive also tried by creating the timer like this:

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

and not adding manually to the runloop but thats no luck either.

Is there anything else needed to ensure that the object is kept in memory ? I thought it was already taken care of by the NSTimer class doing a [target retain] when the timer is created.


James


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >NSTimer: Target object missing when timer fires? (From: dream cat7 <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.