This is the standard way traditional incremental GC works. Typically allocation is done with a protocol like
1. Try to bump a pointer to allocate the memory
2. If there wasn’t enough memory, call a special function (which runs the GC) and try again
This special function may do a big gc pause if necessary or it may just do a small amount of gc work and grant the program some more memory (this way most gc work is shared more evenly with program time). In modern VMs like Java’s, concurrent gc (where gc and mutator run in separate threads possibly needing a pause for some steps) is more popular.
1. Try to bump a pointer to allocate the memory
2. If there wasn’t enough memory, call a special function (which runs the GC) and try again
This special function may do a big gc pause if necessary or it may just do a small amount of gc work and grant the program some more memory (this way most gc work is shared more evenly with program time). In modern VMs like Java’s, concurrent gc (where gc and mutator run in separate threads possibly needing a pause for some steps) is more popular.