• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[LUA] Leaks?

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
I don't know if you LUA leaks but if anyone can skim through my code to see if I have any leaks...

Lua:
function CheckPlayers()
    ForGroup(GetUnitsOfTypeIdAll(FourCC("Edem")), HeroRemove)
end

function HeroRemove()
    local x = GetEnumUnit()
    local playerSlot = GetPlayerSlotState(GetOwningPlayer(x))
    if playerSlot == PLAYER_SLOT_STATE_EMPTY then
        RemoveUnit(x)
    end
end

function deathbounds()
    local regionarray = {}
    for i = 1, 175, 1 do
            regnum = i - 1
            if i >= 11 and i < 101 then
                    regionarray[i] = "gg_rct_Region_0" .. regnum
            elseif i >= 101 then
                    regionarray[i] = "gg_rct_Region_" .. regnum
            else
                    regionarray[i] = "gg_rct_Region_00".. regnum
            end
        print(regionarray[i])     
    end

    print("work")
    local deathRegion = CreateRegion()
    for i = 1, 175, 1 do
        RegionAddRect(deathRegion, _G[string.format(regionarray[i])]);
    end
    local deathTrigger = CreateTrigger()
    TriggerRegisterEnterRegion(deathTrigger, deathRegion, nil)
    TriggerAddAction(deathTrigger, killHero)
end

function killHero()
    print("die bitch")
    KillUnit(GetEnteringUnit()) 
end
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
I couldn't find your garbage collector....
[Lua]Obliterate all GUI leaks with 1 trigger!

It proxies the creation functions to keep track of the created objects. Thanks to Lua's in built garbage collector it will automatically remove objects like locations and groups when no more references to them exist (they leaked) hence fixing the leak.

The only issue was that in 1.31 the JASS hashtable functionality did not count as an Lua reference and so locations and groups only referenced by hashtable might be recycled pre-maturely. Of course this is only an issue for GUI which uses the JASS hashtable functionality. If one writes Lua directly one should use the native table type instead which will track references as expected.
 
Status
Not open for further replies.
Top