Objective-C NSDate memory issue (again)

Posted by Toby Wilson on Stack Overflow See other posts from Stack Overflow or by Toby Wilson
Published on 2010-04-26T08:39:11Z Indexed on 2010/04/26 8:43 UTC
Read the original article Hit count: 326

Filed under:
|
|
|
|

I'm developing a graphing application and am attempting to change the renderer from OpenGL to Quartz2D to make text rendering easier.

A retained NSDate object that was working fine before suddenly seems to be deallocating itself, causing a crash when an NSMutableString attempts to append it's decription (now 'nil').

Build & analyse doesn't report any potential problems.

Simplified, the code looks like this:

NSDate* aDate

-(id)init
{
    aDate = [[NSDate date] retain]
    return self;
}

-(void)drawRect(CGRect)rect
{
    NSMutableString* stringy = [[NSMutableString alloc] init];

    //aDate is now deallocated and pointing at 0x0?
    [stringy appendString:[aDate description]]; //Crash
}

I should stress that the actual code is a lot more complicated than that, with a seperate thread also accessing the date object, however suitable locks are in place and when stepping through the code [aDate release] is not being called anywhere.

Using [[NSDate alloc] init] bears the same effect. I should also add that init IS the first function to be called.

Can anyone suggest something I may have overlooked, or why the NSDate object is (or appears to be) releasing itself?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nsdate