Fandom

WoWWiki

USERAPI EraseTable

104,753pages on
this wiki
Add New Page
Talk13 Share
This page documents a user-defined function that you can copy and paste into your addon. Replace <PREFIX> with your AddOn's prefix to avoid conflicts between different versions of these functions.
User defined functions < EraseTable

EraseTable erases a table, often a good way to reduce garbage creation. Note that erasing a table can be more expensive than letting the GC system reclaim it, so one might prefer simply reallocating a new empty table. Also, note that a hash (as opposed to a 1..n integer-index) will NEVER SHRINK. Each key you ever used will use ~40 bytes and keep doing so until the table is destroyed. If you re-use the same keys this is obviously a nonissue.

For more details on the inner workings of tables and when to reallocate vs when to erase, see Lua object memory sizes and it's talk page.

local function EraseTable(t)
	for i in pairs(t) do t[i] = nil end
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.