So I decided to help nomorholywar with his map and told him I would make him a graveyard system.
How it works:
It creates all the units in the map at once, and stores them in a variable. They are then killed and the corpses are stored somewhere in the map. (May be advised to do it one group of units at a time) When a new unit is needed it moves the first dead unit in the array to the spawn point, and is resurrected by a dummy unit.
Pros:
Your only using the set amount of units instead of creating more and more. The reason for this is because every time a unit is created it uses memory. When the unit is destroyed the memory is still there being used. (Less lag)
Cons:
A lag spike at beginning of game. You have to create them at some point.
Explanation of functions...
init: Creates all the units and dummy casters.
RecycleUnit: Creates an already recycled unit for you.
GarbageUnit: Gets rid of unit in the array and sets it to null. (Free up some space)
GarbageGroup: Gets rid of an entire group of units for player and sets them to null. (Free up some space)