For some reason I can’t use arc, so in my code below..
Foo.h
@interface Foo : NSObject
@property (nonatomic, copy) NSString * string;
@end
Foo.m
@implementation Foo
@synthesize string=_string;
- (void) bar {
self.string = [NSString stringWithFormat:@"test1"];
self.string = [NSString stringWithFormat:@"test2"];
}
-(void) dealloc
{
[_string release];
[super dealloc];
}
@end
The bar method might not always be called, or they can be called multitime.
Is only one release in the dealloc is all needed?
Yes, since you are using properties so setter method will take care of releasing memory allocation.It will allocate memory as follows: