Memory leaks when hiding UITextField shortcuts bar (by setting leadingBarButtonGroups/trailingBarButtonGroups to empty arrays)
|Product:||iOS + SDK
Hiding the shortcuts bar of a UITextField by doing:
inputAssistantItem.leadingBarButtonGroups = 
inputAssistantItem.trailingBarButtonGroups = 
causes instances of UIBarButtonItem (and their associated resources) to leak.
Steps to Reproduce:
1. Open attached minimal demonstration project
2. Build and run on an iPad
3. Tap the "Reload Detail View Controller" button 20 times
4. Open the memory graph debugger in Xcode
5. Open the UIKit section if it isn't already open and you should see that there are 119 instances of UIBarButtonItem live
6. Continue program execution in Xcode
7. Tap "Reload Detail View Controller" once more
8. Open memory graph debugger again
9. You should see that there are 124 instances of UIBarButtonItem live, so each time the view controller is loaded 5 additional instances leak
10. Open TextFieldThatHidesShortcutsBar.swift and comment out the lines that hide the shortcuts bar
11. Build and run the project again
12. Tap the "Reload Detail View Controller" button 20 times
13. Open the memory graph debugger in Xcode
14. You should see that there are no leaked instances of UIBarButtonItem
No memory should leak
Each time a UITextField is loaded which hides its shortcut bar 5 instances of UIBarButtonItem are leaked
iOS 10.2.1 (14D27)
The documented way of hiding the shortcuts bar is to set those arrays to nil, but that isn't possible in Swift, because they're non-optional, and according to this Stack Overflow post leaks still happen even if they are set to nil in an Objective-C project:
iPad mini 2 16GB Wi-Fi (ME276B/A)
'Shortcuts Bar Hiding Memory Leak.zip' was successfully uploaded.
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!