UIDocumentBrowserViewController memory leak

Number:rdar://FB8894765 Date Originated:2020-11-13
Status:Open Resolved:
Product:iPadOS, UIKit Product Version:14.2
Classification:Bug Reproducible:Yes
# UIDocumentBrowserViewController memory leak FB8894765

If an app is using UIDocumentBrowserViewController in a "Multi-Windows" setup on iPad, the document browser of is never released from memory when its window is closed. This makes the whole object graph retained by the document browser to hang in memory, causing all sorts of incorrect behaviour and crashes.

## Steps to reproduce

1. Build and run the demo app in iPad Simulator
2. Add new app window: show home screen (CMD+H) > long-press on app's icon > Show All Windows > Tap (+) in the top right corner
3. Show app switcher: SWIFT+CONTROL+CMD+H
4. Remove the FIRST* app window: swipe it up

## Expected results
`UIWindow` instance is successfully released on `SceneDelegate.sceneDidDisconnect(_:)`, together with its view controller hierarchy, starting with `UIDocumentBrowserViewController` which was assigned to `rootViewController`.

## Actual results
`UIWindow` instance is successfully released on `SceneDelegate.sceneDidDisconnect(_:)` but `UIDocumentBrowserViewController` which was assigned to `rootViewController` hangs in memory, together with its objects and view controller hierachy (e.g. `childen` or `presentedViewController`).

### Footnote
* It is important to remove the first opened app window, not the one that was added by tapping (+) otherwise the whole app gets killed

## Demo


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!