Reputation: 2476
If I'm not using garbage collection and I have a auto property set as retain. Should I release the object in my dealloc or does the generated code handle that for me.
More clearly, will the following code leak memory if I don't release name
in dealloc.
Person.h
@interface Person : NSObject {
}
@property (retain) NSString* name;
@end
Person.m
#import "Person.h"
@implementation Person
@synthesize name;
@end
Upvotes: 1
Views: 210
Reputation: 56
yes this will create memory leak.
You should release it manually or in dealloc to prevent memory leak.
Here is another way to work with this..
//.h file
@interface Person : NSObject {
NSString* name;
}
@end
//.m file
@implementation Person
-(void)ViewdidLoad
{
//You can use this by self.name=[Nsstring StringWithFormat:@""];
} @end
Thanks Shyam Parmar
Upvotes: 0
Reputation: 523304
The retain
/assign
/copy
attributes of a @property
only affects how they would behave in the getter and setter. You do need to manually -release
the ivar in -dealloc
.
Upvotes: 2