Memory leaks when hiding UITextField shortcuts bar (by setting leadingBarButtonGroups/trailingBarButtonGroups to empty arrays)
| Originator: | guillaume.algis | ||
| Number: | rdar://33125266 | Date Originated: | 04-juil.-2017 07:57 PM |
| Status: | Open | Resolved: | |
| Product: | iOS + SDK | Product Version: | 10.3.1 |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
This is a duplicate of radar #31077141
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:
10.3.1
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
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!