Memory leaks when hiding UITextField shortcuts bar (by setting leadingBarButtonGroups/trailingBarButtonGroups to empty arrays)

Originator:jjc1138
Number:rdar://31077141 Date Originated:20170315
Status:Open Resolved:
Product:iOS + SDK Product Version:10.2.1
Classification:Serious Bug Reproducible:Always
 
Area:
UIKit

Summary:
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

Expected Results:
No memory should leak

Actual Results:
Each time a UITextField is loaded which hides its shortcut bar 5 instances of UIBarButtonItem are leaked

Version:
iOS 10.2.1 (14D27)

Notes:
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:
http://stackoverflow.com/questions/40924884/uitextfield-uitextinputassistantitem-hide-and-with-leaks-in-ios

Configuration:
iPad mini 2 16GB Wi-Fi (ME276B/A)

Attachments:
'Shortcuts Bar Hiding Memory Leak.zip' was successfully uploaded.

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!