On Jan 7, 2015, at 9:32 AM, Jonathan Mitchell <[email protected]> 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 protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]