当我试图释放一个实例变量并重新分配一个新值时,会发生问题。实例变量的dealloc问题
我想释放实例变量指向的地址,并为其重新分配一个新值。
的代码如下所示: 的.H
@interface MapPageController : UIViewController<MKMapViewDelegate> {
AddressAnnotationManager *addAnnotation;
}
- (IBAction) showAddress;
@property (nonatomic, retain) AddressAnnotationManager *addAnnotation;
的.M
@synthesize addAnnotation;
- (IBAction) showAddress {
if(addAnnotation != nil) {
[mapView removeAnnotation:addAnnotation];
[addAnnotation release]; // this generates the problem
addAnnotation = nil;
}
addAnnotation = [[AddressAnnotationManager alloc] initWithCoordinate:location];
addAnnotation.pinType = userAddressInput;
addAnnotation.mSubTitle = addressField.text;
}
然而,[addAnnotation release]
,一个EXC_BAD_ACCESS总是走来,如果过程中,通过它运行。
因此我在AddressAnnotationManager
的dealloc
印出的内存地址:
- (void)dealloc {
NSLog(@"delloc Instance: %p", self);
[super dealloc];
}
我打开僵尸,控制台给了我这样的事情:
2010-10-10 17:02 :35.648 [1908:207] delloc实例:0x46c7360
2010-10-10 17:02:54.396 [1908:207] - [AD dressAnnotationManager发布]:发送到释放实例的消息0x46c7360 *
这意味着代码在问题发生之前达到dealloc
。
我已经检查了所有可能发布addAnnotation的地方。但是,我找不到任何。
有没有人碰巧找到问题所在?