Skip to content

Cleanup

APHONIC edited this page Sep 15, 2026 · 2 revisions

Cleanup

Cleanup.lua: the double-pass garbage-collection sweep behind a manual or automatic cleanup feature.

LibAPH.RunDoubleGCPass(opts)

A single collectgarbage("collect") call doesn't settle immediately - reading memory right after it still shows a mid-collection number. This runs the pass twice with settle delays around each, so the before/after numbers reflect a stable state.

Signature: opts.onDone(before_lua, after_lua, freed_lua, before_pool, after_pool, freed_pool) is required.

opts:

Field Default Meaning
onDone Required Called with the before/after/freed numbers
getPoolMB None (defaults to 0) Function returning the console memory-pool reading
settleBeforeMs 500 Delay before the first sample
settleAfterMs 200 Delay after the collection before the second sample
extraPass false Runs a third collectgarbage("collect")
function MyAddon.run_manual_cleanup(force_feedback)
    MyAddon.mem_state = 1
    LibAPH.RunDoubleGCPass({
        getPoolMB = MyAddon.get_console_pool_mb,
        onDone = function(before_lua, after_lua, freed, before_pool, after_pool, freed_pool)
            MyAddon.mem_state = 0
            if freed > 0.001 or freed_pool > 0.001 then
                MyAddon.session_mb_freed = MyAddon.session_mb_freed + freed
            end
        end,
    })
end

Home · Getting Started

Clone this wiki locally