In C# and some Object-Oriented Programming languages, there is the term Garbage Collector. However, in some mid-level programming languages, it is the programmer’s responsibility to remove objects that are no longer needed from memory.
When a code process (process) starts, an empty space is allocated in memory (memory) for this process. This operation is called “Garbage Allocation”, and the allocated space is technically called the Heap Area. The locations of objects in heap memory are held through references (stacks). Objects created at runtime are cleaned from heap memory when they are no longer needed by the application or when their job is done. The “Garbage Collection” mechanism is used for this operation.
1. What happens if there is not enough space in memory?
The Garbage Collector intervenes and all objects that the application does not need are cleaned from the heap area of memory.
In summary; an object was created with the “new” keyword, the application went to heap memory and realized there was no space. The Garbage Collector intervened and the necessary space was allocated.
2. What is the importance of these statements for optimization in mobile games?
We had mentioned the constraints on mobile devices. We must keep system requirements at the lowest possible level, and accordingly, our memory usage should be optimized.
If memory usage is not optimized, our device will frequently call the Garbage Collector to meet allocation requests. These operations generally have a negative impact on our game running on the main thread because the Garbage Collector process is similar to emptying the recycle bin and unfortunately runs on the main thread in Unity.
Calling GC every frame is a consequence of a high amount of data abuse, and as a result, there will be momentary FPS drops. When hundreds of GameObjects are created simultaneously in the scene, this is the primary reason for our FPS to plummet.
Reply by Email