Skip to content

Instantly share code, notes, and snippets.

@ezura
Last active March 4, 2016 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezura/558c092040ecf25ac0e5 to your computer and use it in GitHub Desktop.
Save ezura/558c092040ecf25ac0e5 to your computer and use it in GitHub Desktop.
class MyClass {
var number: Int = 0
lazy var a: () -> () = self.handler()
func handler() -> (() -> ()) {
return {
self.number++
}
}
deinit {
print("deinit")
}
}
do {
let myClass = MyClass()
myClass.a // var a が "self が使われてるクロージャ" を保持するので解放されなくなる
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment