Knowledge Base: Garbage Collector Internals

Unreal Engine’s Garbage Collector is a standard Mark & Sweep collector. This post explains its stages and what it does under the hood.
Summary
These are the major stages of the Garbage Collector:

Mark unreachable.
Mar…

https://dev.epicgames.com/community/learning/knowledge-base/ePKR/unreal-engine-garbage-collector-internals

13 Likes

Are there any plans to implement incremental support for the marking phase? Would this be possible without major rewrite? – Note that Unity is apparently using an Open Source GC ( Boehm–Demers–Weiser) that does support incremental marking and sweep phases. Was this ever considered for UE?

I’m not aware of any such plans. (EDIT: We’re working on it! :+1:)
If the marking phases are having an impact on your game’s performance it might be a symptom of your game having too many UObjects alive. Usually bigger games don’t need more than a couple hundred thousand UObjects alive at any time.

If you’re spawning lots of UObjects with short lifetimes you can look into either re-using them, using FStructs instead of UObjects where you can, or putting them into a GC cluster to reduce garbage collection overhead.

For long-lived UObjects, there’s the option of loading in less / HLODding more.

1 Like

We’re now working on Incremental Reachability Analysis for the Garbage Collector. It’s early on and experimental as of Unreal Engine 5.4 so I don’t recommend turning it on for your shipping projects yet. But if you want to experiment with it in a sandbox check out the documentation on how to turn it on.