OBJECT POOLING
Last updated
Last updated
Object Pool Manager --> a optimization pattern (especially for mobile) that allows the program to recycle game objects instead of instantiating and destroying objects
Within a shooter game, players will be using a ton of bullet game objects
When you constantly instantiate and destroy the bullet game objects the program creates
When the runs out of allocated memory space the is triggered
Program cannot process the next frame until the garbage collection is finished cleaning up
Rule on Garbage Collection --> We do not want it to start its job
To accomplish this rule, we need to create the LEAST amount of Garbage possible
When we use the we reduce the amount of garbage created by recycling Game Objects that are commonly instantiated & destroyed
--> Creates game objects 1 time at the load of the game then recycles them throughout the entire application's lifetime.
Garbage Collection is a memory recovery feature built into the programming language of C#, and is responsible for the following:
--> Manage the allocation & release of memory
--> Serves as an automatic memory manager
A memory allocation is made anytime a script declares an object with a "new" keyword or a value type is boxed
--> When there is not enough memory to allocate an object the Garbage Collector must collect & dispose of garbage memory to make memory available for new allocations
Garbage is created when a object is taking up allocated memory space but is no longer needed in the program.
The Rule to Garbage Collection: We DO NOT want it to start its job
--> this is because when the garbage collector is called, the next frame can not be processed until it has finished cleaning up
GENERATION ONE
GENERATION TWO
GENERATION THREE
Once there is no more space within Gen. 1 to allocate for new objects then the Garbage Collector is called to purge this section of the heap.
--> Any objects that survive this process move to Generation Two
If, once the garbage collector runs on Gen 1, there is still no more room to allocate for new objects then the garbage collector is ran on Gen 2.
--> Objects that survive this process are then moved to Generation Three
Objects remain in this level until they are no longer needed
--> Need to instantiate & destroy objects less often
A heap is an area of pre-reserved computer main storage (memory) that a program process can use to store data in
--> The amount of memory allocated is not known until the program is running
Having a certain amount of heap storage already obtained from the operating system makes it easier for the process to manage storage
--> faster than needing to ask the Operating System for storage every time it is needed
The process manages its allocated heap by requesting a "chunk" of the heap (called a HEAP BLOCK) when needed and returning the blocks when no longer needed and doing occasional Garbage Collection
--> Makes blocks available that are no longer being used and also reorganized the available space in the heap so that it isn't being wasted in small unused pieces
Although each language handles Garbage Collection differently, one common technique is to divide to the memory space into three generations based on the object's longevity...