• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: NSTimer: Target object missing when timer fires?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: NSTimer: Target object missing when timer fires?


  • Subject: Fwd: NSTimer: Target object missing when timer fires?
  • From: dream cat7 <email@hidden>
  • Date: Mon, 30 Jul 2007 18:32:19 +0100


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:
This email sent to email@hidden


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

  • Prev by Date: Interface Builder question : frozen NSTextField
  • Next by Date: Re: Moveable/Resizable "Box" views and blurry frame
  • Previous by thread: NSTimer: Target object missing when timer fires?
  • Next by thread: Re: key-value support for Objective-C "class" variables?
  • Index(es):
    • Date
    • Thread