The following process crashes my application:
- the user opens the view and the request is sent to the server
- the request is running in the background
- user goes to root view
- request completed.
and the following code is executed
[callback loadedDataSource:self];
Meanwhile, other models / views were freed and the message sent to the freed instance.
callbackhas a type idand conforms to the protocol KalDataSourceCallbacks.
How can I avoid sending a message to the selected object?
PS: My question is similar to this question
Edit:
callback nil dealloc ( datasource). , MyDataSource , dealloc RootViewController ( , ).
:
MyDataSource RootViewController:
@property (retain) MyDataSource *dataSource;
@synthesize dataSource;
self.dataSource = [[[MyDataSource alloc] init] autorelease];
kal.dataSource = dataSource;
- (void)dealloc {
[dataSource release];
}
KalViewController . , dataSource , , .
callback:
@property (retain) id<KalDataSourceCallbacks> callback;
@synthesize callback;
- (void)presentingDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id<KalDataSourceCallbacks>)delegate {
self.callback = delegate;
}
- (void)dealloc {
[callback release];
callback = nil;
}
. . callback = nil , dealloc .
MyDataSource , ? , , . , dataSource .
2:
callback nil, , ?
if (callback != nil)
[callback loadedDataSource:self];
.
3:
, :
@property (retain) id<KalDataSourceCallbacks> callback;
@property (assign) id<KalDataSourceCallbacks> callback;
, , loadedDataSource ?