Make maxHeapSize take megablock usage into account (#21927)
This is an implementation of #21927 (closed).
We check that after returning megablocks our megablock usage is below maxHeapSize. We also make sure that if megablock usage is above maxHeapSize that we force a major GC (to give us the best chance of surviving).
I tried to add a test but got stuck. Let me know if anyone has any ideas. It's quite tricky to trigger this behaviour in a test case because we need very high block fragmentation for it to be triggered.