4 ms·
It would be intuitive to me if function closures only retained things they reference It would also be intuitive to me if closures naively retained everything i
by brundolf 2y ago
It would be intuitive to me if function closures only retained things they reference
It would also be intuitive to me if closures naively retained everything in scope
It's bizarre to me that the behavior is "if one closure references something, then all of them retain it"
I guess maybe it's a stack vs heap thing? If nothing retains a variable then it can be kept on the stack, but once it has to outlive the function it has to be moved. Still odd the bookkeeping can't distinguish closures that references it from ones that don't, if it already has to check that for the entire set
- sam_perez 2y agoYeah, this does seem like an odd middle ground. But I suppose it's more about what you're tracking? For example, instead of tracking reference counts to variable, they're tracking reference counts to each scope. Then, if a scope has no more references, the variables it owns are cleaned up.