オブジェクトが解放された後、ガベージを指している壊れたポインタに問題があります。objectAは、別のオブジェクトobjectBからのコールバックのデリゲートです。
objectAは頻繁に割り当てられ、解放されます(私のアプリケーションでは、メニューUIオブジェクトです)。objectAが初期化されるたびに、objectBが初期化され、非同期操作が開始されてから、idデリゲートプロパティを介してobjectAにコールバックされます。ポインタを停止するにはどうすればよいですか:idデリゲートが壊れることはありませんか?
ObjA.m
-(void)dealloc{
[super dealloc];
}
+(id)init{
ObjA *objectA = [[ObjA alloc]init];
return objectA;
}
-(id)init{
if (self == [super init]){
ObjB *objectB = [ObjB initialiseWithDelegate:self];
}
return self;
}
-(void)callback:(id)arg{
//This callback is called from an asynchronous routine from objectB
}
-(void)terminate{
//This is called when I want to remove/release objectA
//Other logical termination code here
[self release];
}
ObjB.m
@synthesize delegate;
+(id)initialiseWithDelegate:(id)delegate{
ObjB *objectB = [[ObjB alloc]init];
[objectB setDelegate:delegate];
return objectB;
}
-(id)init{
if (self == [super init]){
[self beginAsynchronousOperation];
}
return self;
}
-(void)beginAsynchronousOperation{
//Do asynchronous stuff here
}
-(void)finishedAsynchronousOperation{
//Called when asynch operation is complete
if (self.delegate) [self.delegate callback:someargument]; //EXC error. Pointer broke
}