我有以下輔助對象:我是否正確釋放內存?
LikeHelper* likeHelper = [[LikeHelper alloc]init];
likeHelper.delegate = self;
[likeHelper performLike:self.messageID];
[likeHelper release];likeHelper=nil;
performLike會做一些NSURLConnection的東西,然後告訴委託它是否成功。
#pragma mark LikeHelperDelegate Methods
-(void)performLikeFinished:(BOOL)isSuccessful{
if (isSuccessful) {
UIAlertView *alertView;
alertView = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"The message has been liked" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
else {
UIAlertView *alertView;
alertView = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"There was a problem liking your message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
我在正確的位置釋放likeHelper嗎?
它是異步的。這是否意味着我應該將LikeHelper聲明爲一個成員變量,以便我可以從LikeHelperDelegate訪問它? – 2010-10-26 09:28:15
如果我在我的委託方法中釋放它,我不需要在dealloc()中正確釋放它? – 2010-10-26 09:30:39
@Sheehan Alam:正確但要小心,如果您在委託方法中釋放對象,則在委託方法返回時,它將放入可能已被釋放的對象的上下文中。 – JeremyP 2010-10-26 10:43:56