私はこの単純なクラスは、メモリリークの点で大丈夫です知っている。objective-cオブジェクトのメモリ管理
@interface location : NSObject {
NSString *name;
float lat;
float lon;
NSString *subtitle;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, assign) float lat;
@property (nonatomic, assign) float lon;
@end
@implementation location
@synthesize name;
@synthesize lon;
@synthesize lat;
@synthesize subtitle;
-(void)dealloc{
[name release];
[subtitle release];
[super dealloc];
}
@end
@propertyにはretainがありますので、私はdeallocメソッドでリリースしました。今、私の質問は:initメソッドまたは私が作成する他のメソッドの文字列のいずれかを割り当てる場合、私は別のリリースを行う必要がありますか?もしそうなら、いつ?
@implementation location
@synthesize name;
@synthesize lon;
@synthesize lat;
@synthesize subtitle;
-(void) init{
name = [[NSString alloc] init];
}
-(void)dealloc{
[name release]; // IS THIS CORRECT?!
[subtitle release];
[super dealloc];
}
@end
おかげで、最初の例では、私の質問を解決しました。 –