Re: Strange controls behaviour in sheet modal window
Graham Cox
OK, if anyone’s interested, I figured this out.
toggle quoted message
Show quoted text
This is in an ARC project, and it’s a memory management issue. The window controller was being returned by a class method that just alloc+initWithWindowNibName: ‘d it and returned it. The client code then invoked the method on it that displays it as a sheet. The probem is that left no reference to the window controller, so ARC duly released it. The window itself was shown completely normally and displayed as a sheet, with all its controls fully working. The controls targetted the now-released window controller, but controls now use a zeroing weak reference, so that ended up as nil. That caused the controls to try and send the action to First Responder, which didn’t implement the action, so it just beeped. Keeping a strong reference to the window controller for the duration of the sheet fixes the issue. While I fully get this, I’m not sure if there’s a better way to handle it than having a temporary ‘strong’ property for the controller within the client object. Usually for dialogs like this, I don’t need such a property, and in manual retain/release land, I can make put a self-retaining behaviour around the document modal sheet operation of the dialog so that client code is spared the need for it. Obviously with ARC I can’t do that, so the onus is on the client code to do it. This actually makes the client code much MORE memory management aware with ARC than without! A bit ironic that. Is there a better solution? —Graham On 5 Dec 2017, at 2:50 pm, Graham Cox <graham@...> wrote: |
|