Memory leak caused by checking protocol conformance in a switch

Number:rdar://40287604 Date Originated:16/05/18
Status:Open Resolved:
Product:iOS/Swift Product Version:
Classification:Bug Reproducible:Always
A memory leak is caused when checking if a UIViewController subclass conforms to a protocol that is not a class protocol.

This looks like a recurrence (or alternate version) of the bug described here...

I have also given an in depth description of the bug here...

Steps to Reproduce:
I have created a very small project to show this.

The code is as follows...

```protocol MyProtocol {}

class ViewController: UIViewController, UINavigationControllerDelegate {
    override func viewDidLoad() {
        navigationController?.delegate = self
    func navigationController(_ navigationController: UINavigationController,
                              animationControllerFor operation: UINavigationControllerOperation,
                              from fromVC: UIViewController,
                              to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        switch (fromVC, toVC) {
        case (is MyProtocol, is MyProtocol):
            print("🍎 NOOOOOO!")
            return nil
            print("🍏 Yippee!")
            return nil
    deinit {
        print(#function, "View Controller")

class AnotherViewcontroller: UIViewController, MyProtocol {
    deinit {
        print(#function, "Another View Controller")

The storyboard contains a UINavigationController with rootViewController of `ViewController`. This pushes on to `AnotherViewController`.

Expected Results:
When popping back to `ViewController` the `AnotherViewController` should be deallocated.

Actual Results:
It isn't deallocated. It causes a memory leak.

Version 9.3.1 (9E501)
iPhone 8 plus simulator


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!