Is Go’s defer used to optimize the GC? I thought it was just syntax sugar to make sure people wouldn’t forget to close file handles and things like that..?
You can probably say the same about heap allocated memory, but GC'd languages make the choice the non-deterministic release of heap allocations are fine. But there are resources where you can't play the same game (open files, connections, locks) and you need a way to deterministically close them.