NSSearchField saves and restores the previous first responder

Originator:peter
Number:rdar://23608913 Date Originated:19-Nov-2015 05:40 PM
Status:Open Resolved:
Product:OS X Product Version:10.11.1
Classification:Crash Reproducible:Always
 
Summary:
NSSearchField saves the previous first responder with it becomes first responder.  It then makes that previous first responder the new window first responder when it loses focus (eg for Hide Application).  It does this even if the previous first responder has been removed from the window.  Even if the retain that it holds is the only remaining retain of the view.  Needless to say making an almost deallocated view no longer even in the window the first responder of the window can easily result in crashes (eg if the view accesses its now deallocated delegate for example).

Steps to Reproduce:
Create a window with a NSTextView and an NSSearchField.  Set the text view to be focused.  Then setHidden on the view so the NSSearchField field gains focus.  Then remove the NSTextView from the window and remove any reference to it.  The NSSearchField retains a reference to the NSTextView so it will not be deallocated, which in itself would be a problem for some custom views.  Then hide the application.  NSSearchField (in [NSSearchField _windowResignedKeyStatus:]) will set the first responder of the window back to the NSTextView that is no longer even in the window.

Expected Results:


Actual Results:


Version:
10.11.1

Notes:


Configuration:
It appears to be any time NSSearchField gets focus by the removal of the currently focuses field from the window.  There may be more to it, this is as deeply as I can go without access to the source for NSSearchField

Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!