Every object created in a game will take up memory. And when the game stops using that object it needs to be destroyed and removed from the game. This is done with something that’s called Garbage Collection or GC for short.
Now, in pure C++ you do your own memory allocations for the objects you create, you hold the refrence to them, and you’re responsible for Garbage Collecting that object when you stop using it.
And this is one of the main reasons why people are afraid of C++ and why they think it’s hard to learn it, especially for Unreal Engine where you use a ton of objects in your game and who want’s to manage all that craziness, right?
Well, the good news is that we don’t need to do that inside Unreal Engine because the GC in UE is built and it looks over the memory periodically and it collects objects that have no reference to them.
Before we start, this post is not meant for complete beginners. If you don’t know what are objects, references, and pointers, I suggest you first read the 3 blog posts I’ll put below in the order they are placed:
Learn To Code In C++ For Unreal Engine – Pointers
Learn To Code In C++ For Unreal Engine – References
Learn To Code In C++ For Unreal Engine – Classes And Objects