Optimizing memory
We discussed how to profile and optimize two pieces of hardware—the CPU and GPU—but there is another piece of hardware that plays a key role in our game—RAM. This is the place where we put all of our game's data. Games can be memory-intensive applications, and unlike several other applications, they are constantly executing code, so we need to be especially careful about that.
In this section, we will examine the following memory optimization concepts:
- Memory allocation and the garbage collector
- Using the Memory Profiler
Let's start discussing how memory allocation works and what role garbage collection plays here.
Memory allocation and the garbage collector
Each time we instantiate an object, we are allocating memory in RAM, and in a game, we will be allocating memory constantly. In other programming languages, aside from allocating the memory, you need to manually deallocate it, but C# has a garbage collector...