gc.CollectGarbageEveryFrame
gc.CollectGarbageEveryFrame
#Overview
name: gc.CollectGarbageEveryFrame
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Used to debug garbage collection...Collects garbage every N frames if the value is > 0.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of gc.CollectGarbageEveryFrame is to assist in debugging garbage collection in Unreal Engine. It allows developers to force garbage collection to occur at regular intervals during gameplay.
This setting variable is primarily used by the Unreal Engine’s core runtime system, specifically the garbage collection subsystem. It’s referenced in the Engine module, as evident from its location in the UnrealEngine.cpp file.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, which means it’s disabled by default. Developers can change this value at runtime using console commands or through configuration files.
The associated variable CVarCollectGarbageEveryFrame directly interacts with gc.CollectGarbageEveryFrame. They share the same value and purpose.
Developers must be aware that enabling this variable (setting it to a value greater than 0) will have a significant impact on performance. It should only be used for debugging purposes and not in production builds.
Best practices when using this variable include:
- Only enable it when specifically debugging garbage collection issues.
- Use it in conjunction with profiling tools to understand the impact on performance.
- Set it to a reasonable value (e.g., every 100 or 1000 frames) to avoid excessive performance degradation.
- Remember to disable it after debugging is complete.
Regarding the associated variable CVarCollectGarbageEveryFrame:
The purpose of CVarCollectGarbageEveryFrame is to provide a programmatic interface to control the gc.CollectGarbageEveryFrame setting. It’s an instance of TAutoConsoleVariable
This variable is used within the Engine module, specifically in the UEngine::ConditionalCollectGarbage() function. When its value is greater than 0, it triggers garbage collection every N frames, where N is the value of the variable.
The value of CVarCollectGarbageEveryFrame is set through the console variable system and can be changed at runtime.
Developers should be aware that this variable directly controls the behavior of the garbage collection system and can have a significant impact on performance.
Best practices for using CVarCollectGarbageEveryFrame include:
- Use GetValueOnGameThread() to safely access its value from the game thread.
- Consider the performance implications when enabling it, especially with low interval values.
- Use it in conjunction with other debugging tools to get a comprehensive view of memory management in your game.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:1589
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarCollectGarbageEveryFrame(
TEXT("gc.CollectGarbageEveryFrame"),
0,
TEXT("Used to debug garbage collection...Collects garbage every N frames if the value is > 0."));
static TAutoConsoleVariable<int32> CVarContinuousIncrementalGC(
TEXT("gc.ContinuousIncrementalGC"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarCollectGarbageEveryFrame
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:1588
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarCollectGarbageEveryFrame(
TEXT("gc.CollectGarbageEveryFrame"),
0,
TEXT("Used to debug garbage collection...Collects garbage every N frames if the value is > 0."));
static TAutoConsoleVariable<int32> CVarContinuousIncrementalGC(
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:1891
Scope (from outer to inner):
file
function void UEngine::ConditionalCollectGarbage
Source code excerpt:
}
if (const int32 Interval = CVarCollectGarbageEveryFrame.GetValueOnGameThread())
{
if (0 == (GFrameCounter % Interval))
{
ForceGarbageCollection(true);
}
}