[swift-dev] Lazy var and deinit

Alexandr.moq alex at moqod.com
Thu Apr 21 04:29:57 CDT 2016


Should SWIFT initialize a variable in deinit method if it has not been initialized? 

For example: 
```swift
class A {
	lazy var b = B()
	deinit {
		b.clean()
	}
}
var a = A()
a.b.doSomething() //1: variable was created
a = A() //2: "clean" method was called for "b" variable
a = A() //3: instance of A from step 2 should killed and "deinit" method is called. In this method "b" variable will be created, "clean" will be called and "b" will be killed. So, is it ok or better if swift doesn’t create lazy variables in deinit if variable is not created yet
```
To be honest, I don’t know which topic I should use. Because I don’t know, it’s propose, bug or something else. 


More information about the swift-dev mailing list