It's the actual garbage collection that might be expensive, but since that process deals with the fragmentation, there is no need to keep a data structure with available blocks of memory around.
That's also the reason why, depending on the patterns of memory usage, a GC can be faster than malloc+free.
Isn't one of the advantages of a GC environment that malloc is basically free? Afaik the implementation of malloc_in_gc comes down to
It's the actual garbage collection that might be expensive, but since that process deals with the fragmentation, there is no need to keep a data structure with available blocks of memory around.That's also the reason why, depending on the patterns of memory usage, a GC can be faster than malloc+free.