I’m developing an iPhone application.
I have the following property:
@property (nonatomic, retain) Point2D* endPoint;
And this is a method on the same class:
- (id)initWithX:(CGFloat)x Y:(CGFloat)y;
{
if (self = [super init])
{
endPoint = [[Point2D alloc] initWithX:x Y:y];
...
}
And finally the dealloc method on the same class:
- (void)dealloc {
[endPoint release];
[super dealloc];
}
My question is it this code correct?
endPoint = [[Point2D alloc] initWithX:x Y:y];
Or maybe I have to do an autorelease here.
Your assignment
endPoint = [[Point2D alloc] initWithX:x Y:y];does not increase the retainCount, so if you want to keep endPoint to use later you don’t use autorelease here.
Or you can use like this
self.endPoint = [[[Point2D alloc] initWithX:x Y:y] autorelease];=> This assignment will increase the counter of endPoint.