• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[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
 
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.
Back
Top