• 🏆 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] Memory Monitor

A simple snippet that might help the mapmakers check out the potential of memory leaks.
Applicable only to v.1.31.

Lua:
do
    local _frame
    local text     = "|cffff40ffMemory Used (kB):|r "
    function CreateOverwatch()
        if _frame then
            return
        end
        local world    = BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)
        _frame         = BlzCreateFrameByType("TEXT", "GarbageMonitor", world, "", 0)
        BlzFrameSetSize(_frame, 0.12, 0.05)
        BlzFrameSetAbsPoint(_frame, FRAMEPOINT_TOPRIGHT, 0.80, 0.45)
        BlzFrameSetScale(_frame, 1.25)
        BlzFrameSetText(_frame, text)
        BlzFrameSetEnable(_frame, false)
        BlzFrameSetFocus(_frame, false)
        BlzFrameSetText(_frame, text .. tostring(math.floor(collectgarbage('count'))))
    end
    function MonitorOverwatch()
        if not _frame then
            return
        end
        local timer = CreateTimer()
        TimerStart(timer, 0.01, true, function()
            local mem = collectgarbage('count')
            mem       = math.floor(mem)
            BlzFrameSetText(_frame, text .. tostring(mem))
        end)
    end
end

To activate the snippet, call CreateOverwatch before MonitorOverwatch.
 
Last edited:
Level 4
Joined
Mar 25, 2021
Messages
18
Same for me.
Reason seems to be, the collectgarbage function doesn't currently exist (i.e. _G['collectgarbage'] is nil).
I haven't ever used it, but it must have existed in 1.32.9. Otherwise MyPad's snippet would never have worked.
To my understanding blizzard removed all(?) garbage collector api:s in 1.32. Read it somewhere but can't find source.
 
Last edited:
Top