So, in a worst-case scenario, when a new memory allocation is being requested by our game, the CPU would have to spend cycles completing the following tasks before the allocation is finally completed:
- Verify that there is enough contiguous space for the new object.
- If there is not enough space, iterate through all known direct and indirect references, marking everything they connect to as reachable
- Iterate through all of these references again, flagging unmarked objects for deallocation
- Iterate through all flagged objects to check whether deallocating some of them would create enough contiguous space for the new object
- If not, request a new memory block from the OS to expand the heap
- Allocate the new object ...