当我试图释放一个实例变量并重新分配一个新值时,会出现问题。
我想释放一个实例变量指向的地址,并为其重新分配一个新值。
代码如下所示:
.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_访问。
因此,我在
dealloc
属于
AddressAnnotationManager
:
- (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]
它意味着代码到达
释放内存
我已经检查了所有可能发布addAnnotation的地方。但是,我找不到。
有没有人碰巧发现问题所在?