Re: ARC query
Re: ARC query
- Subject: Re: ARC query
- From: Ken Thomases <email@hidden>
- Date: Wed, 07 Jan 2015 12:02:16 -0600
On Jan 7, 2015, at 9:32 AM, Jonathan Mitchell <email@hidden> wrote:
> I use this construct quite a lot without really thinking about it under ARC
> I don’t retain a reference to the alert.
>
> Does -beginSheetModalForWindow: completionHandler: cause the receiver to be retained until after the completion handler returns?
>
> NSAlert *alert = [NSAlert new];
> alert.alertStyle = NSWarningAlertStyle;
> alert.messageText = @“Do not touch!";
> [alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
> [alert orderOut:self];
> }];
Well, given your code, it is retained indirectly at least. -beginSheetModalForWindow:completionHandler: has to copy the block, since it survives past its scope. The block has a reference to alert, so, when it is copied, it retains alert until the block copy is fully released and deallocated.
By the way, the documentation for -beginSheetModalForWindow:completionHandler: specifically says that you don't need to call -orderOut: in your completion handler. It will be done after your completion handler exits. Which, by the way, indicates that the alert is retained until then, too.
Short answer: yes, the alert is retained.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >ARC query (From: Jonathan Mitchell <email@hidden>) |