HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

All buildings in Same place vs Memory Leaks

01-30-2005, 11:51 PM#1
QuakeII_best
Today I learnt something about memory leaks and other things.... So I decided to "fix" the memory leaks in my map.

To start I used a basic trigger to create each building in my map.
Code:
Basic
    Events
        Map initialization
    Conditions
    Actions
        Unit - Create 1 Aura Shop for Player 1 (Red) at (Center of Rect_Barrack[1]) facing Default building facing (270.0) degrees
Since I had to do this many times and for different buildings I put each of my rect in a variable. Then used the "Create unit" trigger and a "For every integer" loop to place them.

Trying to practice my "anti-memory leaks" I decided to make fix the leaks for those triggers.

Result: The trigger I'm posting + All buildings placed in the center of the map on top of each other (except the barracks cuz they use P1 start location).

I read somewhere that the variables can "lose" their value if there was a wait in the trigger. There's no wait in this trigger... If you got any idea what I can do to fix them please let me know...
Code:
Variable Init for Shops
    Events
    Conditions
    Actions
        -------- Regions-Shops --------
        Set Rect_ShopWENSC[1] = Shop W <gen>
        Set Rect_ShopWENSC[2] = Shop E <gen>
        Set Rect_ShopWENSC[3] = Shop N <gen>
        Set Rect_ShopWENSC[4] = Shop S <gen>
        Set Rect_ShopWENSC[5] = Shop C <gen>
        Set Rect_Fountain[1] = Shop 1 <gen>
        Set Rect_Fountain[2] = Shop 2 <gen>
        Set Rect_Fountain[3] = Shop 3 <gen>
        Set Rect_Fountain[4] = Shop 4 <gen>
        Set Rect_ShopBase[1] = Shop 1N <gen>
        Set Rect_ShopBase[2] = Shop 1W <gen>
        Set Rect_ShopBase[3] = Shop 2E <gen>
        Set Rect_ShopBase[4] = Shop 2N <gen>
        Set Rect_ShopBase[5] = Shop 3E <gen>
        Set Rect_ShopBase[6] = Shop 3S <gen>
        Set Rect_ShopBase[7] = Shop 4W <gen>
        Set Rect_ShopBase[8] = Shop 4S <gen>
        -------- Regions-Spawn --------
        Set Rect_Spawn[1] = Spawn P01 <gen>
        Set Rect_Spawn[2] = Spawn P02 <gen>
        Set Rect_Spawn[3] = Spawn P03 <gen>
        Set Rect_Spawn[4] = Spawn P04 <gen>
        Set Rect_Spawn[5] = Spawn P05 <gen>
        Set Rect_Spawn[6] = Spawn P06 <gen>
        Set Rect_Spawn[7] = Spawn P07 <gen>
        Set Rect_Spawn[8] = Spawn P08 <gen>
        Set Rect_Spawn[9] = Spawn P09 <gen>
        Set Rect_Spawn[10] = Spawn P10 <gen>
        Set Rect_Spawn[11] = Spawn P11 <gen>
        Set Rect_Spawn[12] = Spawn P12 <gen>
        -------- Regions-Towers --------
        Set Rect_Tower[1] = Tower 01 <gen>
        Set Rect_Tower[2] = Tower 02 <gen>
        Set Rect_Tower[3] = Tower 03 <gen>
        Set Rect_Tower[4] = Tower 04 <gen>
        Set Rect_Tower[5] = Tower 05 <gen>
        Set Rect_Tower[6] = Tower 06 <gen>
        Set Rect_Tower[7] = Tower 07 <gen>
        Set Rect_Tower[8] = Tower 08 <gen>
        Set Rect_Tower[9] = Tower 09 <gen>
        Set Rect_Tower[10] = Tower 10 <gen>
        Set Rect_Tower[11] = Tower 11 <gen>
        Set Rect_Tower[12] = Tower 12 <gen>
        -------- Units-Shop --------
        Set Unit_ShopsWENSC[1] = Armor and Artifacts
        Set Unit_ShopsWENSC[2] = Armor and Artifacts
        Set Unit_ShopsWENSC[3] = Weapons and Orbs
        Set Unit_ShopsWENSC[4] = Weapons and Orbs
        Set Unit_ShopsWENSC[5] = Mercenaries, Mana and Life
Code:
Creation of Buildings
    Events
        Map initialization
    Conditions
    Actions
        -------- Shops --------
        For each (Integer A) from 1 to 8, do (Actions)
            Loop - Actions
                Set Rect_TempPoint = (Center of Rect_ShopBase[(Integer A)])
                Unit - Create 1 Aura Shop for Neutral Passive at Rect_TempPoint facing Default building facing (270.0) degrees
                Point - Remove Rect_TempPoint
        For each (Integer A) from 1 to 5, do (Actions)
            Loop - Actions
                Set Rect_TempPoint = (Center of Rect_ShopWENSC[(Integer A)])
                Unit - Create 1 Unit_ShopsWENSC[(Integer A)] for Neutral Passive at Rect_TempPoint facing Default building facing (270.0) degrees
                Point - Remove Rect_TempPoint
        -------- Barracks and Towers --------
        For each (Integer A) from 1 to 12, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Player_InGame[(Integer A)] Equal to True
                    Then - Actions
                        Set Rect_TempPoint = (Center of Rect_Tower[(Integer A)])
                        Unit - Create 1 Boom Tower for (Player((Integer A))) at Rect_TempPoint facing Default building facing (270.0) degrees
                        Unit - Create 1 Barracks (Mad) for (Player((Integer A))) at ((Player((Integer A))) start location) facing Default building facing (270.0) degrees
                        Point - Remove Rect_TempPoint
                    Else - Actions
        -------- Fountains --------
        For each (Integer A) from 1 to 4, do (Actions)
            Loop - Actions
                For each (Integer B) from 1 to 3, do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                Player_InGame[((Integer B) + (((Integer A) - 1) x 3))] Equal to True
                            Then - Actions
                                Set Rect_TempPoint = (Random point in Rect_Fountain[(Integer A)])
                                Unit - Create 1 Fountain of Energy for (Player(((Integer B) + (((Integer A) - 1) x 3)))) at Rect_TempPoint facing Default building facing (270.0) degrees
                                Point - Remove Rect_TempPoint
                            Else - Actions
01-31-2005, 09:03 AM#2
Anitarf
Well, from what you pasted here, it seems that your variable init has no events, meaning it doesn't run at all. This trigger shoud run before you use any of the variables, if you use them before this, they won't be set yet, so they will be null.

Also, as far as I know, it's not the regions but the points that are problematic when memory leaks are concerned. So, while your region array may help you spawn units organisedly with loops, it does nothing for object handle leaks that happen whenever you create a point object, in your case "centre of region". Not that this matters, though, since you only do this a couple of times in a single-run trigger, the memory leak is insignificant.
01-31-2005, 09:49 AM#3
QuakeII_best
You are so right and I'm a mentally retarded person... why do I have to make those silly mistakes (lol).

Well, it is just for practice... I have a few of periodic events that do need to need to be memory leak free (some are periodic and others are for every time a unit dies).

Question: are those trigger clear of memory leaks? I just wanna know if I can do the same thing for the important triggers...
02-01-2005, 09:44 AM#4
wiebbe
yup, by the looks of it you have gotten the basics down :P

btw, i still would do this trigger memory leak free, because just learning yourself to do that, you will do it everytime without thinking ;)
02-01-2005, 11:19 AM#5
Anitarf
Yes, it seems clear of memory leaks now (you are using some enhanced editor it seems, I'm used to destroying points with jass custom scripts :) ). Keep in mind, though, for later triggers, that point objects are not the only ones that leak: same goes for unit groups, which is the next most popular source of mem leaks, and special effects. Then there are also some more obscure objects like player groups etc...

Well, anyway, if you read any mem leak tutorial, you should already know all these things, silly me to explain them.