4 ms·
Interesting, and I think that is not specific to Go, other mark-and-sweep GCs (Java, C#) should behave the same. Which means that creating short lived objects
by deepsun 2y ago
Interesting, and I think that is not specific to Go, other mark-and-sweep GCs (Java, C#) should behave the same.
Which means that creating short lived objects (like iterators for loops, or some wrappers) is ok.
- int_19h 2y agoIt should be noted that in C#, at least, the standard pattern is to use value types for enumerators, precisely so as to avoid heap allocations. This is the case for all (non-obsolete) collections in the .NET stdlib - e.g. List<T>.Enumerator is a struct.
- ted_dunning 2y agoNot entirely. Go still doesn't have a generational collector so high allocation rates cause more GC's that must examine long-lived objects. As such, short-lived objects have little impact in Java (thank god for that!). They will have second order effects in Go.