2 ms·
GCs in general can batch memory allocations, reallocations and frees. With idiomatic non GC programs, an object that is freed is deallocated at that point of e
by lelanthran 3y ago
GCs in general can batch memory allocations, reallocations and frees.
With idiomatic non GC programs, an object that is freed is deallocated at that point of execution.
Think of a loop running 15 times that calls a function which allocates objects, uses them and then returns.
In a GC language, there is only a single free. In a non GC language, each return of that function will cause a free to occur.
There's some other interesting optimisations that can only be done in a GC language.
The only way to get those optimisations in a non-gc language is to effectively implement your own allocation and deallocation using pools.
- diarrhea 3y agoThat is a great insight, thanks. I have always been under the impression that non-GC performance is strictly better under all circumstances, but your example is an obvious counterpoint.