# How to smooth out the garbage collector activity?

**URL:** <https://forums.unrealengine.com/t/how-to-smooth-out-the-garbage-collector-activity/2260234>\
**Category:** Debugging, Optimization, & Profiling\
**Tags:** unreal-engine, CPP, question\
**Created:** [January 5, 2025, 1:27am UTC](https://forums.unrealengine.com/t/how-to-smooth-out-the-garbage-collector-activity/2260234 "2025-01-05T01:27:00Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [January 5, 2025, 9:15pm UTC](https://forums.unrealengine.com/t/how-to-smooth-out-the-garbage-collector-activity/2260234/4 "2025-01-05T21:15:05Z")

</div>

Hi @3dRaven and @Randy_Seth

> [@3dRaven](#):
>
> Any pointers that you set to nullptr will be marked as pending kill and will wait for the GC to become fully invalidated and their memory cleaned up.

I only have four pointers set to nullptr (they are FRunable threads) they are destroyed right at the end of everything (in the EndPlay() function of the AAIController).

> [@3dRaven](#):
>
> If this is the start of a level after switching from a main menu then perhaps the GC is cleaning up the old level at the beginning?

> [@Randy\_Seth](#):
>
> It seems the spikes in garbage collection could be due to unreferenced objects or scene transitions, particularly if they’re from previous levels.

> [@Randy\_Seth](#):
>
> Optimizing data handling at level transitions might also reduce these spikes.

In the bars at the beginning it is not the case… I am running the map in standalone mode, without running menus beforehand. But it happens in the bars at the end… effectively at the end it is traveling to the main menu.

* * *

```auto
@echo off
cd %~dp0
cd..
cd..
set EDITOR="C:\Program Files\Epic Games\UE_5.5\Engine\Binaries\Win64\UnrealEditor.exe"
set PROJECT="%cd%\Catharsis.uproject"
set MAPPATH="/Game/Game/Maps/GamePlay/Arena01/L_Arena01"
set "RUNASSERVER=%MAPPATH% -server -port=7777 -log"
set "CPUTRACE=-cpuprofilertrace -loadtimetrace"
set "RUNASCLIENT=127.0.0.1:7777 -game -windowed -log -resx=1000 -resy=500 -winx=100 -winy=100"
:: start "" "C:\Program Files\Epic Games\UE_5.5\Engine\Binaries\Win64\UnrealEditor.exe" "%cd%\Catharsis.uproject" %MAPPATH% -game -windowed -log -resx=1000 -resy=500 -winx=100 -winy=100 -client
start "" %EDITOR% %PROJECT% %RUNASSERVER% %CPUTRACE%
start "" %EDITOR% %PROJECT% %RUNASCLIENT%
pause

```

* * *

What happens at the beginning I think may be due to this.

The first bar is because of a python script (I’m not using python so it must be something in the engine).

 ![1-Python+Widget](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/d/14d9a47f11b6140c226cc718df166bec81c87768.png)

The Second bar is the Garbage Collector and FlushAsyncLoading…  
The garbage collector has a very large CPU time, but FlushAsyncLoading CPU time is almost infinite. (I need to check this… I think a material is causing problems here).

 ![2-GC+FlushAsyncLoading (Material)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/3/e/53eaee299f4d90f3aef9ce594d6f659017cc5619.png)

Then the GC is doing a Perform Reachability Analysis (It takes a lot of CPU time too).

 ![4+GCPerformReachabilityAnalisis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/8/bb8ca3692aef185568cfba2567bbe19994340e85.png)

Then this happen (WinPumpMessage) Huge bar…

 ![5-WinPumpMessage](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/2/28229578915651bc0f2348c95de6016e42b37d2c.png)

Then the GC is doing a another Perform Reachability Analysis in the meadle of the graph (This time the bar is smaller than the previous one… but it is still big)).

 ![7-GC](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/9/e/e9e622689e6b0f764ffec79b43715be9b0cf8e61.png)

And again a few frames ahead

 ![9-GC](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/6/2/7627e24f83ebd5f5ed355e86117db40b8b185f78.png)

And another WinPumpMessage

 ![11-WinPumpMessage](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/3/f537e48ba135875cf988a8e3eb2596f93708c6f0.png)

* * *

So it seems that what causes most of the spikes at the beginning, middle, and end of the graph is the following.

-Perform Reachability Analysis  
-WinPumpMessage

* * *

> [@3dRaven](#):
>
> Niagara has it’s own pooling system internally so it will probably reserve memory for it’s own particles & reuse them.

I’m using this flag  
`PoolingMethod = ENCPoolMethod::ManualRelease;`  
It allows me to have a valid reference of the Niagara component (I hope it to use a pool internally too).

> [@Randy\_Seth](#):
>
> Ensure your particle system pools are efficiently managing instances

I guess I’m doing it that way… all my particle systems are created at the beginning and destroyed at the end… halfway through they are reused (objects pooling).

> [@Randy\_Seth](#):
>
> check for non-particle temporary data.

Ok, this is new to me… I don’t know what you mean… I’ll look into it.

* * *

\*Maybe there is a way to configure “Perform Reachability Analysis” to be more frequent?  
-Perhaps if analysis is more frequent then there are fewer things to analyze and therefore less time to do them. (It’s just a guess)…

\*Looking for solution for WinPumpMessage too…

> [@PumpMessage makes spikes in game thread](https://forums.unrealengine.com/t/pumpmessage-makes-spikes-in-game-thread/433611/2):
>
> How do you build and run the project? [PumpMessage()](http://api.unrealengine.com/INT/API/Runtime/Slate/Framework/Application/FSlateApplication/PumpMessages/index.html) is part of the debugging system. Check if the framedrop occurs in [Test state](https://docs.unrealengine.com/en-us/Programming/Development/BuildConfigurations) build.

I guess I’ll have to try it on the compiled and packaged version.  
Unless there is a way to disable the debugging system.  
Maybe I can do that with a console command?

* * *

Thank you very much for the help @3dRaven and @Randy_Seth

---

_[View the full topic](https://forums.unrealengine.com/t/how-to-smooth-out-the-garbage-collector-activity/2260234)._
