Memory leak with UISheetPresentationController

Hello,

It appears that there is a memory leak when utilizing a UISheetPresentationController. Please take a look at this simple project available here.

On the iOS 16.4 simulator for iPhone 14, if I dismiss the sheet, SheetViewController is successfully deinitialized. However, when I run this code on a real device (iPhone XR, iOS 16.4.1), the deinit of SheetViewController is not triggered. It seems like the presentation controller which holds a reference to SheetViewController stays in memory, captured by a closure.

Here is the memory leak caused by iOS:

Is this bug already known to the community? Should I report it? Is there any workaround for this issue?

Thank you.

Seems my issue could be the same thing that's causing this issue, as I would assume that sheets in SwiftUI are just SheetViewController under the hood in UIKit. Crossposting a similar bug that appears on SwiftUI on the latest version of iOS too 16.4. https://developer.apple.com/forums/thread/729197.

Looks like an Apple bug. Appears to be fixed when running against iOS 17 simulators.

Memory leak with UISheetPresentationController
 
 
Q