I'm new to Objective-C (from java background), so apologies if this question is too trivial.
Suppose i have two classes, where one holds a reference to another, as such:
@interface PostOffice
@property (nonatomic, strong) MailGuy *mailGuy;
@end
@implementation PostOffice
-(void)getMailmanToSendMail {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
self.mailGuy = [[MailGuy alloc] init];
[self.mailGuy sendMail];
}
}
@end
and for MailGuy:
@interface MailGuy () <MFMailComposeViewControllerDelegate>
@end
@implementation MailGuy
-(void)sendMail {
NSLog(@"send mail");
[self.viewController presentViewController:mailViewController animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
// upon dismissal, how do i get the PostOffice instance to release this MailGuy instance?
}
@end
How do i get the PostOffice to release the MailGuy?? i only know when it should be free based on the callback. but i don't want to store a reference to the PostOffice? or do i ? and does it matter that i'm instantiating the MailGuy from a background thread?
any help would be appreciated. thanks!