In this snippet ```@Composable fun Toolbar(conten...
# compose
d
In this snippet
Copy code
@Composable
fun Toolbar(content: @Composable () -> Unit) { ... }

fun slotBuilder(text: String): @Composable () -> Unit = { Text(text) }

@Composable
fun Screen() {
  Toolbar { Text("hello") } // A
  Toolbar(content = slotBuilder("hello")) // B
}
Is
A
and
B
equivalent allocation-wise? In each case a new lambda will be created on each recomposition or am I wrong here?
a
both a and b are same and yes new instance of lambda will be created on each recomposition
l
Lambdas will be remembered implicitly iirc.
d
Hmm, I do not recall reading about implicitly remembered lambdas anywhere. I guess I'll just check 🙂
a
no i don't think it's remembered implicitly but can wrap with remember
Copy code
remember {
    {}
}
I mostly prefer method ref to viewModel but for some rare case I use above one
d
Can't wrap it with
remember
, because it's a composable function
Also if I'm not mistaken, debugging indicates that variant
B
has new lambda instance on each recomposition, while variant
A
has the same lambda instance on each recomposition. I'm not seeing clearly why this is so.
l
Lambdas will be remembered implicitly iirc.
I was talking about A case. For B case, I don't know either 😕 Maybe because it's as return type.