Jules
Jules

Reputation: 660

releasing a retained property thats been autoreleased?

Hey all. Ive got a headache trying to get my head around this. I have a retained property of type NSNumber. When I use this property I instantiate it with an autoreleased NSNumber. When dealloc is called I then get bad access telling me that Im releasing something that has already been released. Heres some code.

@interface RadarAnnotation : NSObject <MKAnnotation> {    
 }
@property (retain, nonatomic) NSNumber *latitude;
@end

@implementation RadarAnnotation

@synthesize latitude;

- (CLLocationCoordinate2D)coordinate
 {
coordinate.latitude = [self.latitude doubleValue];
return coordinate;
}

 -(void) dealloc {
[super dealloc];
[latitude release];//error is here when mapViewController is popped off stack.
}

Here is how I instantiate the property in my mapViewController :

poi.latitude = [NSNumber numberWithDouble:map.centerCoordinate.latitude];

What am I doing wrong? Many thanks. Jules.

Upvotes: 0

Views: 105

Answers (1)

jaminguy
jaminguy

Reputation: 25940

You should be calling [super dealloc] at the end of the dealloc method.

Upvotes: 1

Related Questions