2 ms·
Go distinguishes at the type level between pointers and stack-based data, so it's much easier to have pervasive value types and only GC things which are being p
by Manishearth 11y ago
Go distinguishes at the type level between pointers and stack-based data, so it's much easier to have pervasive value types and only GC things which are being pointerified. Add escape analysis to that and it's amazing.
Of course, there's a teensy-weensy mental cost that you have to pay in Go where you actually think about these pointers, since you have to explicitly add `&` and `*` for it to work well. This is far less than the cost required to think about malloc and free in C, but it's a cost, and part of the cost-benefit tradeoff between Go and Java. You have to think about pointers a little bit, and in return you get decently efficient memory management.
Go's GC is basically "I will GC-manage what you ask me to and even then try to avoid it when possible"
Java, on the other hand, doesn't distinguish between this and has to try and figure everything out itself. The programmer can't hint to the compiler that something doesn't need GC; the compiler has to figure this out on its own. This can't be changed backwards-compatibly, since it involves changing defaults.
Java's GC is "I will GC-manage everything and sometimes try to avoid it"