Removing a view controller from memory when instantiating a new view controller

You need only to use:

EDIT Swift 4.2

self.dismiss(animated:true, completion: nil)

The rest of work is doing by ARC

To help you during your debug you can add also this code:

 if let app = UIApplication.shared.delegate as? AppDelegate, let window = app.window {
        if let viewControllers = window.rootViewController?.children {
            for viewController in viewControllers {
                print(viewController.debugDescription)
            }
        }
    }

An important reason for this problem is related to the memory management!

if you have 'strong reference' or 'delegate' or 'closure' or other things like this, and you didn't managed these objects, your view controller has strong reference and never be closed.

you should get 'deinit' callback in view controller after than viewDidDisappear called. if 'deinit' not called so your view controller still is alive and it has strong reference.