How to use Garbage Collection? Best experience

I wonder about how to use garbage collection in UE4.

What do you suggest and how to use it

Any detailed advice is welcome.

  • Consequences about running in each actor destroy
  • Consequences about running in each minute
  • Whats the best way to use?

Thank you!

The GC is automated, so best design practice is to let it manage when things are destroyed when possible. With AActor it’s a bit different, as with UObjects you can simply MarkPendingKill(), but AActor does not allow this. Their references are held by UWorld.

So I would figure out a way to remove them from any reference, then GC will see they have no chain to the root set and clean them. If you manage that, then all you need to do is make them invisible to the game.

If you’re needing to constantly spawn and destroy actors, it’s a better practice to simply reuse and reinitialize actors rather than destroy and spawn a new one.

What you offering is giving a lot spawning slowness. So I needed to force GC from GEngine always. Problem solved.
I wonder to have answer not to slowdown spawns when spawning and destroying same object continously.