• 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
Re: NSTimer and seg faults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer and seg faults


  • Subject: Re: NSTimer and seg faults
  • From: "Hamish Allan" <email@hidden>
  • Date: Wed, 12 Mar 2008 21:03:19 +0000

Hi Gregory,

The method [NSDate date] returns an autoreleased object, which has
been dealloced by the time your NSTimer fires.

I'd recommend reading the documentation on memory management, starting with:

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

Best wishes,
Hamish

On Wed, Mar 12, 2008 at 8:56 PM, Gregory Short <email@hidden> wrote:
>         Howdy all, first-time poster here. I'm pretty new to Objective-C and
>  it's associated run-time environment, so I apologize if this is a
>  total newbie question that has been answered before (I couldn't find
>  anything, but I might not know where to look.)
>         My problem is this: I have an NSTimer which I set up in my NSView's -
>  awakeFromNib method. Also in -awakeFromNib, I set create an NSDate
>  object as part of the NSView. This all works fine. The problem is,
>  when my timer fires, if I try to do anything at all with the NSDate
>  object I created before, the program chokes. Here's the relevant
>  portion of the code (I've stripped out what appears to be irrelevant;
>  if anyone wants to see more, that's fine.)
>
>  BlobView.h:
>
>  @interface BlobView : NSOpenGLView
>  {
>         NSTimer* updateTimer;
>         NSDate* lastUpdate;
>  }
>
>  - (void) updateTimer: (NSTimer *) timer;
>
>  @end
>
>
>
>  BlobView.m:
>
>  @implementation BlobView
>
>  - (void) awakeFromNib {
>         lastUpdate = [NSDate date];
>         NSLog(@"%lf", [lastUpdate timeIntervalSinceNow]); // This works fine
>
>         updateTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 / 30.0
>                 target: self
>                 selector: @selector(updateTimer:)
>                 userInfo: nil
>                 repeats: YES];
>  }
>
>  - (void) updateTimer: (NSTimer *) timer {
>         NSLog(@"%lf", [lastUpdate timeIntervalSinceNow]); // This produces a
>  SIGBUS
>  }
>
>  @end
>  _______________________________________________
>
>  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

References: 
 >Re: Cocoa-dev Digest, Vol 5, Issue 393 (From: Daniel Child <email@hidden>)
 >Re: Cocoa-dev Digest, Vol 5, Issue 393 (From: John Stiles <email@hidden>)
 >Re: runtime error (From: Daniel Child <email@hidden>)
 >NSTimer and seg faults (From: Gregory Short <email@hidden>)

  • Prev by Date: Re: NSTimer and seg faults
  • Next by Date: Re: Core Animation geometry, layer hosting, and resolution independence
  • Previous by thread: Re: NSTimer and seg faults
  • Next by thread: Re: NSTimer and seg faults
  • Index(es):
    • Date
    • Thread