objective-c releasing uninitialized class members in dealloc method

Posted by Dude Man on Stack Overflow See other posts from Stack Overflow or by Dude Man
Published on 2010-05-23T03:49:55Z Indexed on 2010/05/23 3:50 UTC
Read the original article Hit count: 244

Filed under:
|
|

Regarding over-releasing. Say I have a instance variable defined in Test.h

NSString *mystring;

In my implementation Test.m I do not initialize the variable mystring anywhere. But I release it in dealloc:

-(void)dealloc {
    [mystring release];
}

Is this now over-released? I've been doing the following in dealloc to avoid any issues, however, is this really necessary?

-(void)dealloc {
     if (mystring) [mystring release];
}

It seems that [nil release] shouldn't do anything, can someone verify this with class members?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c