Comment

Comment by brundolf

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

parent brundolf 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton