UITextField instances are never destroyed and cause significant performance degradation due to memory and CPU overhead.

Number:rdar://36182782 Date Originated:December 21, 2017
Status:OPEN Resolved:
Product:iOS + SDK Product Version:
Classification:Bug Reproducible:Always


Any UITextField objects created are never deallocated causing serious memory overhead in applications that display large numbers of UITextFields over their lifetime. The UITextField does not need to be added to the view hierarchy, simply initializing a text field in a local variable will result in an abandoned object when the reference falls out of scope. 

Steps to Reproduce:
Create a UITextField using the default initializer or through interface builder. Leave the scope that the UITextField instance is valid in so that all references to the object are destroyed or remove the containing view from the view hierarchy and remove all references to the view ensuring the containing view is deallocated. 

Expected Results:
The UITextField is deallocated when references to the instance and it's containing view (if added to the view hierarchy) is deallocated. 

Actual Results:
The UITextField is never deallocated and remains in the application's memory space for the lifetime of the application. 

iOS 11.2 & 11.2.1 

A sample application has been provided to illustrate the problem. The applications displays an initial view controller containing 4 UIButton's:
1. "Show Text Field Table": Tapping this button displays a table view with 1000 rows. Each row contains 12 UITextFields.
2. "Show Text View Table": Tapping this button displays a table view with 1000 rows. Each row contains 12 UITextViews. 
3. "Show View Controller": Tapping this button displays a view controller containing a single UITextField and a single UITextView. 
4. "Create UITextField": Tapping this button creates a function local UITextField instance, which is not assigned to a variable or added to a view hierarchy.  

The looking at the memory graph during execution of the sample will show that leaving any of the views containing a UITextField results in the text fields being abandoned not deallocating with the containing view controller. Tapping button 4 the application also illustrates that any initialized UITextField is never deallocated. In contrast all instances of UITextView are destroyed when their parent view is deallocated.


Apple Developer Forum thread regarding this issue


By Chris.Morse at Jan. 2, 2018, 2:36 p.m. (reply...)

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!