Re: crash when accessing instance variables in class implementation
Re: crash when accessing instance variables in class implementation
- Subject: Re: crash when accessing instance variables in class implementation
- From: Andrew Farmer <email@hidden>
- Date: Thu, 9 Aug 2007 00:19:40 -0700
On 08 Aug 07, at 23:42, Aleksander Valtyshev wrote:
Hello
I have two classes one is:
Engine.h
- (id) init {
self = [super init];
if (self != nil) {
NSLog(@"Crap OK");
start_time = [NSDate date];
You need to retain start_time. It's getting autoreleased and probably
causing your crash.
If you haven't done so already, review the Cocoa memory management
rules. Understanding them is crucial.
-(void) Verlet{
NSLog([[NSNumber numberWithDouble:[start_time
timeIntervalSinceNow]] stringValue]);
}
Using variable format strings is dangerous - if the string contains a
'%', it'll try to read an argument and probably crash. Use
NSLog(@"%f", [start_time timeIntervalSinceNow])
instead. This probably isn't causing the problem you're observing,
but it's good practice (and simpler, too).
_______________________________________________
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