FROM : Hank Heijink (Mailinglists)
DATE : Wed Mar 12 22:08:27 2008
You're getting an autoreleased date and autoreleased timer from the
methods you call, but you're not retaining either your timer our your
date, so they'll both be gone after you leave awakeFromNib.
Read the memory management guide for how all this works:
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
>
In the meantime try
lastUpdate = [[NSDate alloc] init];
and put a retain around your scheduledTimer. Also, your updateTimer
callback doesn't need an NSTimer * argument.
Good luck!
Hank
On Mar 12, 2008, at 4:56 PM, Gregory Short 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_removed>)
>
> 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/hank.list
> %40runbox.com
>
> This email sent to hank.<email_removed>
>
DATE : Wed Mar 12 22:08:27 2008
You're getting an autoreleased date and autoreleased timer from the
methods you call, but you're not retaining either your timer our your
date, so they'll both be gone after you leave awakeFromNib.
Read the memory management guide for how all this works:
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
>
In the meantime try
lastUpdate = [[NSDate alloc] init];
and put a retain around your scheduledTimer. Also, your updateTimer
callback doesn't need an NSTimer * argument.
Good luck!
Hank
On Mar 12, 2008, at 4:56 PM, Gregory Short 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_removed>)
>
> 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/hank.list
> %40runbox.com
>
> This email sent to hank.<email_removed>
>
| Related mails | Author | Date |
|---|---|---|
| Gregory Short | Mar 12, 21:56 | |
| Andrew Farmer | Mar 12, 22:02 | |
| Hamish Allan | Mar 12, 22:03 | |
| Hank Heijink (Mail… | Mar 12, 22:08 | |
| Gregory Short | Mar 12, 22:16 |






Cocoa mail archive

