当我试图释放我的一个实例变量并重新为其分配一个新值时,就会出现问题。
我想释放实例变量指向的地址,并为其重新分配一个新值。
代码如下所示: .h
@interface MapPageController : UIViewController<MKMapViewDelegate> {
AddressAnnotationManager *addAnnotation;
}
- (IBAction) showAddress;
@property (nonatomic, retain) AddressAnnotationManager *addAnnotation;
他们
@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 总是会出现。
dealloc
因此,我在of中打印出内存地址AddressAnnotationManager
:
- (void)dealloc {
NSLog(@"delloc Instance: %p", self);
[super dealloc];
}
我打开 Zombie,控制台给了我这样的信息:
2010-10-10 17:02:35.648 [1908:207] delloc 实例:0x46c7360
2010-10-10 17:02:54.396 [1908:207]-[AddressAnnotationManager release]:消息发送到已释放实例 0x46c7360 *
这意味着代码dealloc
在问题发生之前到达。
我已经检查了我可以发布 addAnnotation 的所有可能的地方。但是,我找不到任何东西。
有没有人碰巧发现问题所在?