During a previous discussion about anonymous structs, one of the stated benefits of structs is that they can be stack allocated while closures are boxed. I am curious, is this always the case?
So for instance, if I have code like this:
func foo(_ block: ()->()) {
block()
}
while true {
foo {
// do something
}
}
It would seem like the compiler should essentially be able to optimize the closure out of existence, and you shouldn't need retain and release here, because the lifetime of the closure will not escape the scope it's declared in. However is this actually the case?