views:

58

answers:

1

I subclassed NSObject:

#import <Foundation/Foundation.h>


@interface STObject : NSObject {
    NSString *message_type;
    NSString *twitter_in_reply_to_screen_name;
}

@property(nonatomic, copy) NSString *message_type;
@property(nonatomic, copy) NSString *twitter_in_reply_to_screen_name;

@end

My implementation looks like:

#import "STObject.h"

@implementation STObject
@synthesize message_type, twitter_in_reply_to_screen_name;

@end

Do I need to create a dealloc method for my two properties where I release the strings?

+3  A: 

Yes. The the properties won't be automatically -release'd with @synthesize.

-(void)dealloc {
   [message_type release];
   [twitter_in_reply_to_screen_name release];
   [super dealloc];
}
KennyTM
Or, equivalently, `self.message_type = nil; self.twitter_in_reply_to_screen_name = nil;`
Noah Witherspoon
I prefer releasing the instance variables, because your program will explode if you reference the ivar after it's been deallocated; hence, setting as `nil` will keep your program from exploding, but it will also hide bugs.
Jonathan Sterling
Jonathan Sterling: That's only a problem if you do it *after* sending `[super dealloc]`, and it's a problem whichever way you do it. The correct solution is to send the `release` messages yourself (not use properties, in case the accessors—which may have been overridden—are not pure http://developer.apple.com/mac/library/documentation/DeveloperTools/gcc-4.0.1/gcc/Function-Attributes.html#index-g_t_0040code_007bpure_007d-function-attribute-1206 ) and do `[super dealloc]` last.
Peter Hosey