Garbage collection tactics
One strategy to minimize garbage collection problems is concealment by manually invoking the GC at opportune moments when we're certain the player would not notice. Garbage collection can be manually invoked by calling System.GC.Collect().
Good opportunities to invoke a collection may occur while loading between levels, when the gameplay is paused, shortly after a menu interface has been opened, during cutscene transitions, or any break in gameplay when the player would not witness, or care about, a sudden performance drop. We could even use the Profiler.GetMonoUsedSize() and Profiler.GetMonoHeapSize() methods at runtime to determine whether a garbage collection needs to be invoked soon.
We can also cause the deallocation ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access