I have 1 more question i am worried about, custom values of my summoners are numbers from 1530 up to 1550 if max index of my array unit is for example 1550 then wont it allocate 1550 places in memory even tho most of them are empty? im just afraid of memory leaks
The max array size of a variable is 32,768, so as long as your map doesn't have 32,768 units at the same time you'll be fine. Also, Bribe's Unit Indexing system recycles unused custom values, meaning if a unit dies then it's Custom Value becomes available to use by a newly created unit. So it's extremely hard to reach this limit since you need 32,768 units all living at the same time.
But more importantly, you don't need to set the default size of most Arrays. Keeping their array size at 1 will cause them to automatically adjust when needed.
HOWEVER, Unit Groups, Player Groups, and Timers are the exception to this rule and won't work properly if you simply rely on the default array size of 1. But there's a workaround where you can Create the Group/Timer yourself using Custom script which fixes this issue, which is what I'm doing in my first trigger:
-
Custom script: set udg_SummonGroup[udg_CV] = CreateGroup()
Also, you're correct about the max index allocating 1550 places in memory despite most being empty, but those are NOT memory leaks and it's really not an issue to have a lot of Array variables.
A memory leak is when you lose track of something and cannot get rid of it. Some things in Warcraft 3 will automatically destroy/remove themselves so it's not always a problem, but certain things do cause memory leaks if you don't destroy/remove them yourself. For example, this trigger has a memory leak:
-
Set Variable TempLoc = Center of map
-
Special Effect - Create a Thunderclap special effect at TempLoc
-
Special Effect - Create a Thunderclap special effect at TempLoc
-
Special Effect - Destroy (Last created effect)
-
Custom script: call RemoveLocation(udg_TempLoc)
We're properly managing the Point memory leak by using TempLoc and then Removing it, HOWEVER, we never Destroy our first Thunderclap special effect, and now we can never destroy it because we've lost track of it. We either have to Destroy it BEFORE creating the second Special Effect or store it in a variable so we can keep track of it and destroy it later on. It's the act of "losing track of it" that makes it a memory leak.