WoW:USERAPI EraseTable: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
 
(Add note that hashes never shrink)
Line 2: Line 2:
__NOTOC__
__NOTOC__


Erases a table, often a good way to reduce garbage creation.  Note that erasing a table is generally more expensive than letting the GC system reclaim it, so one might prefer simply reallocating a new empty table.
Erases a table, often a good way to reduce garbage creation.  Note that erasing a table is generally 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.


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

Revision as of 16:23, 31 December 2007

This page documents a user-defined function that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.

User defined functions


Erases a table, often a good way to reduce garbage creation. Note that erasing a table is generally 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.

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