Memory leak in iOS 8+ after setting window.rootViewController while another view controller is presented

Number:rdar://21404408 Date Originated:16/6/2015
Status:Open Resolved:
Product:iOS Product Version:8.3
Classification:Other bug Reproducible:Always
Background: Our app requires the user to log in every time they use it, and logs the user out when entering background or after a period of inactivity. When logging out, the application replaces the window's current rootViewController with a new instance of our login view controller. This is to ensure all views and view controllers used during the user’s session are removed.

If a view controller presentation is in progress when the window's -rootViewController is replaced, then the presented view controller, the presenting view controller, and their views are not deallocated.

Steps to Reproduce:
1. Create an application with three view controllers, A, B, and C.
2. In application:didFinishLaunchingWithOptions:, create a window and set its root view controller to an instance of A.
3. Use -presentViewController:animated:completion: to present an instance of B from A.
4. Without dismissing B, set the window's root view controller to an instance of C.

Expected Results:
View controllers A and B are deallocated.

Actual Results:
View controllers A and B leak, together with their views.

iOS 8.3 Simulator

In iOS 7.1, the view controllers A and B are deallocated as expected.

iOS 8.3 Simulator



Seems like fixed in iOS 13

By anton.tikhonoff at April 7, 2020, 3:01 p.m. (reply...)

still occurring in iOS 12.1

This is still occuring on iOS 12.0.1

By kcankaynak at Oct. 23, 2018, 1:43 p.m. (reply...)

This is still occurring on iOS 11.4

By alexjfigueroa at July 31, 2018, 6:58 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!