If i create an new "Single View Application" project with xcode(6.3.2) and add only a deinit function to the ViewController. Run app, close app. Deinit is never called! I tested it with several devices and the simulator.
deinit {
println("deinit:")
}
Why is that? Is that the standard behaviour? What can i do to make it work?
/* Edit */ After reading the comments i put this code to my Viewcontroller.
import UIKit
class A {
func test() {
println("A test")
}
deinit {
println("A deinit")
}
}
class ViewController: UIViewController {
var a:A? = A()
override func viewDidLoad() {
super.viewDidLoad()
println("ViewController viewDidLoad")
a?.test()
}
override func viewDidDisappear(animated:Bool) {
println("ViewController viewDidDisappear")
a = nil
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
println("ViewController didReceiveMemoryWarning")
}
deinit {
println("ViewController deinit")
a = nil
}
}
Now i get
ViewController viewDidLoad:
A test
ViewController viewDidDisappear:
A deinit
Does this mean that i have to cleanup my objects by hand within the viewDidDisappear call because the view controllers deinit function is not reliable?