<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://addonstudio.org/mw1/index.php?action=history&amp;feed=atom&amp;title=WoW%3AHOWTO%3A_Use_Tables_Without_Generating_Extra_Garbage</id>
	<title>WoW:HOWTO: Use Tables Without Generating Extra Garbage - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://addonstudio.org/mw1/index.php?action=history&amp;feed=atom&amp;title=WoW%3AHOWTO%3A_Use_Tables_Without_Generating_Extra_Garbage"/>
	<link rel="alternate" type="text/html" href="https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;action=history"/>
	<updated>2026-06-12T00:59:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6126&amp;oldid=prev</id>
		<title>Move page script: Move page script moved page HOWTO: Use Tables Without Generating Extra Garbage to WoW:HOWTO: Use Tables Without Generating Extra Garbage without leaving a redirect</title>
		<link rel="alternate" type="text/html" href="https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6126&amp;oldid=prev"/>
		<updated>2023-08-15T04:48:30Z</updated>

		<summary type="html">&lt;p&gt;Move page script moved page &lt;a href=&quot;/wiki/WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&quot; title=&quot;WoW:HOWTO: Use Tables Without Generating Extra Garbage&quot;&gt;HOWTO: Use Tables Without Generating Extra Garbage&lt;/a&gt; to &lt;a href=&quot;/wiki/WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&quot; title=&quot;WoW:HOWTO: Use Tables Without Generating Extra Garbage&quot;&gt;HOWTO: Use Tables Without Generating Extra Garbage&lt;/a&gt; without leaving a redirect&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:48, 15 August 2023&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key addonstu_asmw2:diff::1.12:old-6123:rev-6126 --&gt;
&lt;/table&gt;</summary>
		<author><name>Move page script</name></author>
	</entry>
	<entry>
		<id>https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6123&amp;oldid=prev</id>
		<title>Bear at 06:25, 23 May 2020</title>
		<link rel="alternate" type="text/html" href="https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6123&amp;oldid=prev"/>
		<updated>2020-05-23T06:25:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 06:25, 23 May 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{wowlua}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Creating number and strings values is pretty efficient in Lua, Numbers do not have any additional data structure associated with them and are freed immediately when no longer used. Strings are hashed and stacked together with same strings, so creating 10000 copies of &amp;quot;Hello, world!&amp;quot; or creating and freeing it repeatedly will not produce garbage. Tables, however, always take memory when created that always becomes garbage when table is no longer used. If you do not want to create unnecessary garbage either avoid using tables unless it is really necessary or, in case several of your throw-away tables use same set of fields, or each new calculation uses superset of field of previous table, use only one table instead of creating new table for every calculation. For example, if you need to sort 20 values, display result and then sort another 30 and display them too, most people would write:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Creating number and strings values is pretty efficient in Lua, Numbers do not have any additional data structure associated with them and are freed immediately when no longer used. Strings are hashed and stacked together with same strings, so creating 10000 copies of &amp;quot;Hello, world!&amp;quot; or creating and freeing it repeatedly will not produce garbage. Tables, however, always take memory when created that always becomes garbage when table is no longer used. If you do not want to create unnecessary garbage either avoid using tables unless it is really necessary or, in case several of your throw-away tables use same set of fields, or each new calculation uses superset of field of previous table, use only one table instead of creating new table for every calculation. For example, if you need to sort 20 values, display result and then sort another 30 and display them too, most people would write:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l114&quot;&gt;Line 114:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 115:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Finally, let me stress once again: this works best when you have table of same size or with same set of fields. As you see from the last example, buttons differ by two fields and function now has to take care of that. Forgetting this while using this approach can produce some very funny and hard to track bugs. And clearing table from previous values can degrade performance if there are many fields to clear on each run. Another thing to be aware of is that unlike &amp;lt;tt&amp;gt;UIDropDownMenu_AddButton&amp;lt;/tt&amp;gt;, some function may store table reference and check values from it at some point in future, hoping that nobody else uses this table. When such function do that in future only to get something else that was initially passed, they tend to mess things up in quite spectacular ways. Check the target function to make sure that it doesn&amp;#039;t store passed table.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Finally, let me stress once again: this works best when you have table of same size or with same set of fields. As you see from the last example, buttons differ by two fields and function now has to take care of that. Forgetting this while using this approach can produce some very funny and hard to track bugs. And clearing table from previous values can degrade performance if there are many fields to clear on each run. Another thing to be aware of is that unlike &amp;lt;tt&amp;gt;UIDropDownMenu_AddButton&amp;lt;/tt&amp;gt;, some function may store table reference and check values from it at some point in future, hoping that nobody else uses this table. When such function do that in future only to get something else that was initially passed, they tend to mess things up in quite spectacular ways. Check the target function to make sure that it doesn&amp;#039;t store passed table.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HOWTOs|Use Tables Without Generating Extra Garbage]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HOWTOs|Use Tables Without Generating Extra Garbage]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Bear</name></author>
	</entry>
	<entry>
		<id>https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6125&amp;oldid=prev</id>
		<title>WoWWiki&gt;IAmParadox: info.func having the wrong &quot;pseudo code&quot; caused me to have no idea why my dropdown wasn&#039;t working for far longer than was necessary....</title>
		<link rel="alternate" type="text/html" href="https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6125&amp;oldid=prev"/>
		<updated>2008-06-20T21:58:13Z</updated>

		<summary type="html">&lt;p&gt;info.func having the wrong &amp;quot;pseudo code&amp;quot; caused me to have no idea why my dropdown wasn&amp;#039;t working for far longer than was necessary....&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:58, 20 June 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l63&quot;&gt;Line 63:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 63:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.text = &amp;quot;Action Button1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.text = &amp;quot;Action Button1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.value = &amp;quot;Value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.value = &amp;quot;Value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.func = DoSomething&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.func = &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function() &lt;/ins&gt;DoSomething&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;() end;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(info);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(info);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l69&quot;&gt;Line 69:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 69:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.text = &amp;quot;Action Button2&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.text = &amp;quot;Action Button2&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.value = &amp;quot;Another value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.value = &amp;quot;Another value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.func = DoSomethingElse&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   info.func = &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function() &lt;/ins&gt;DoSomethingElse&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;() end;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(info);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(info);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  end&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l104&quot;&gt;Line 104:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 104:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.text = &amp;quot;Action Button1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.text = &amp;quot;Action Button1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.value = &amp;quot;Value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.value = &amp;quot;Value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.func = DoSomething&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.func = &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function() &lt;/ins&gt;DoSomething&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;() end;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.text = &amp;quot;Action Button2&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.text = &amp;quot;Action Button2&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.value = &amp;quot;Another value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.value = &amp;quot;Another value to act on&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.func = DoSomethingElse&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   workingTableForInitMenu.func = &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function() &lt;/ins&gt;DoSomethingElse&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;() end;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  end&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key addonstu_asmw2:diff::1.12:old-6124:rev-6125 --&gt;
&lt;/table&gt;</summary>
		<author><name>WoWWiki&gt;IAmParadox</name></author>
	</entry>
	<entry>
		<id>https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6124&amp;oldid=prev</id>
		<title>WoWWiki&gt;Rowaasr13 at 10:53, 16 February 2007</title>
		<link rel="alternate" type="text/html" href="https://addonstudio.org/mw1/index.php?title=WoW:HOWTO:_Use_Tables_Without_Generating_Extra_Garbage&amp;diff=6124&amp;oldid=prev"/>
		<updated>2007-02-16T10:53:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Creating number and strings values is pretty efficient in Lua, Numbers do not have any additional data structure associated with them and are freed immediately when no longer used. Strings are hashed and stacked together with same strings, so creating 10000 copies of &amp;quot;Hello, world!&amp;quot; or creating and freeing it repeatedly will not produce garbage. Tables, however, always take memory when created that always becomes garbage when table is no longer used. If you do not want to create unnecessary garbage either avoid using tables unless it is really necessary or, in case several of your throw-away tables use same set of fields, or each new calculation uses superset of field of previous table, use only one table instead of creating new table for every calculation. For example, if you need to sort 20 values, display result and then sort another 30 and display them too, most people would write:&lt;br /&gt;
&lt;br /&gt;
 local temporaryTable&lt;br /&gt;
 &lt;br /&gt;
 temporaryTable={}&lt;br /&gt;
 for idx=1, 20 do&lt;br /&gt;
  temporaryTable[idx]=GetSomeDataByIndex(idx)&lt;br /&gt;
 end&lt;br /&gt;
 DisplayResult(table.sort(temporaryTable))&lt;br /&gt;
 &lt;br /&gt;
 temporaryTable={} -- inefficient&lt;br /&gt;
 for idx=1, 30 do&lt;br /&gt;
  temporaryTable[idx]=GetSomeOtherDataByIndex(idx)&lt;br /&gt;
 end&lt;br /&gt;
 DisplayResults(table.sort(temporaryTable))&lt;br /&gt;
&lt;br /&gt;
This example would create one table, trash it after calculation and create another throw-away table again. Removing extra table constructor in line marked with &amp;quot;-- inefficient&amp;quot; will save you memory. Such optimization would be especially effective inside long loops or frequently called function.&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
 local function OftenCalledSortingFunction()&lt;br /&gt;
  local temporaryTable={}&lt;br /&gt;
  for idx=1, 20 do&lt;br /&gt;
   temporaryTable[idx]=GetSomeDataByIndex(idx)&lt;br /&gt;
  end&lt;br /&gt;
  return table.sort(temporaryTable)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Placing call to this in frequently called event or even worse in &amp;quot;OnUpdate&amp;quot; handler is a sure way to fill your memory with garbage fast.&lt;br /&gt;
&lt;br /&gt;
New:&lt;br /&gt;
&lt;br /&gt;
 local workingTableForOftenCalledSortingFunction={} -- we can create it once and reuse it because we always sort exactly 20 values&lt;br /&gt;
 local function OftenCalledSortingFunction()&lt;br /&gt;
  for idx=1, 20 do&lt;br /&gt;
   workingTableForOftenCalledSortingFunction[idx]=GetSomeDataByIndex(idx)&lt;br /&gt;
  end&lt;br /&gt;
  return table.sort(workingTableForOftenCalledSortingFunction)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
You can futher maximize savings if some other functions too use table with same size/set of field by sharing this working table between them.&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s example straight from many addons that create UI dropdowns:&lt;br /&gt;
&lt;br /&gt;
 local function MyAddon_InitMenu()&lt;br /&gt;
  local info&lt;br /&gt;
  &lt;br /&gt;
  info = {}&lt;br /&gt;
  info.text = &amp;quot;Settings Button1&amp;quot;&lt;br /&gt;
  info.value = &amp;quot;Some value&amp;quot;&lt;br /&gt;
  info.checked = PlayerSettings[&amp;quot;Setting1&amp;quot;]&lt;br /&gt;
  UIDropDownMenu_AddButton(info);&lt;br /&gt;
  &lt;br /&gt;
  info = {};&lt;br /&gt;
  info.text = &amp;quot;Settings Button2&amp;quot;&lt;br /&gt;
  info.value = &amp;quot;Some other value&amp;quot;&lt;br /&gt;
  info.checked = PlayerSettings[&amp;quot;Setting2&amp;quot;]&lt;br /&gt;
  UIDropDownMenu_AddButton(info);&lt;br /&gt;
  &lt;br /&gt;
  -- end of settings buttons&lt;br /&gt;
  &lt;br /&gt;
  info = {};&lt;br /&gt;
  info.text = &amp;quot;Action Button1&amp;quot;&lt;br /&gt;
  info.value = &amp;quot;Value to act on&amp;quot;&lt;br /&gt;
  info.func = DoSomething&lt;br /&gt;
  UIDropDownMenu_AddButton(info);&lt;br /&gt;
  &lt;br /&gt;
  info = {};&lt;br /&gt;
  info.text = &amp;quot;Action Button2&amp;quot;&lt;br /&gt;
  info.value = &amp;quot;Another value to act on&amp;quot;&lt;br /&gt;
  info.func = DoSomethingElse&lt;br /&gt;
  UIDropDownMenu_AddButton(info);&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
If you ever written something like that, then your addon contributes 4 tables (in this example) to garbage every time this menu is displayed. And if you&amp;#039;ve used loops to dynamically generate long menus (listing all characters&amp;#039; profiles, for example) then you&amp;#039;ve lost even more. For efficient use of memory you can define &amp;lt;tt&amp;gt;info&amp;lt;/tt&amp;gt; once, removing all &amp;lt;tt&amp;gt;info = {}&amp;lt;/tt&amp;gt; lines and adding &amp;lt;tt&amp;gt;info.checked = nil&amp;lt;/tt&amp;gt; string after end of settings buttons, to ensure that checked/unchecked state of last settings button doesn&amp;#039;t appears on action buttons. This will reduce your losses to one trashed table per call.&lt;br /&gt;
&lt;br /&gt;
And, just like in previous example, you can use one permanent working table and eliminate garbage generation completely:&lt;br /&gt;
&lt;br /&gt;
 -- UIDropDownMenu_AddButton only needs table to conveniently pass arguments by name&lt;br /&gt;
 -- All values are copied to their correct places inside UIDropDownMenu_AddButton&lt;br /&gt;
 -- and it doesn&amp;#039;t need table we passed any longer after that. This allows us to&lt;br /&gt;
 -- reuse same table for passing parameters, since we know that reference to this&lt;br /&gt;
 -- table won&amp;#039;t be saved anywhere as long as we use same fields and thus overwrite&lt;br /&gt;
 -- previous values automatically without need to clear working table in some way.&lt;br /&gt;
 &lt;br /&gt;
 local workingTableForInitMenu={}&lt;br /&gt;
 local function MyAddon_InitMenu()&lt;br /&gt;
  workingTableForInitMenu.func=nil -- erase value that could be there from last call&lt;br /&gt;
  &lt;br /&gt;
  workingTableForInitMenu.text = &amp;quot;Settings Button1&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.value = &amp;quot;Some value&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.checked = PlayerSettings[&amp;quot;Setting1&amp;quot;]&lt;br /&gt;
  UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;br /&gt;
  &lt;br /&gt;
  workingTableForInitMenu.text = &amp;quot;Settings Button2&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.value = &amp;quot;Some other value&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.checked = PlayerSettings[&amp;quot;Setting2&amp;quot;]&lt;br /&gt;
  UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;br /&gt;
  &lt;br /&gt;
  -- end of settings buttons&lt;br /&gt;
  &lt;br /&gt;
  workingTableForInitMenu.checked=nil -- erase value that could be there from last settings button&lt;br /&gt;
  &lt;br /&gt;
  workingTableForInitMenu.text = &amp;quot;Action Button1&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.value = &amp;quot;Value to act on&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.func = DoSomething&lt;br /&gt;
  UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;br /&gt;
  &lt;br /&gt;
  workingTableForInitMenu.text = &amp;quot;Action Button2&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.value = &amp;quot;Another value to act on&amp;quot;&lt;br /&gt;
  workingTableForInitMenu.func = DoSomethingElse&lt;br /&gt;
  UIDropDownMenu_AddButton(workingTableForInitMenu)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Finally, let me stress once again: this works best when you have table of same size or with same set of fields. As you see from the last example, buttons differ by two fields and function now has to take care of that. Forgetting this while using this approach can produce some very funny and hard to track bugs. And clearing table from previous values can degrade performance if there are many fields to clear on each run. Another thing to be aware of is that unlike &amp;lt;tt&amp;gt;UIDropDownMenu_AddButton&amp;lt;/tt&amp;gt;, some function may store table reference and check values from it at some point in future, hoping that nobody else uses this table. When such function do that in future only to get something else that was initially passed, they tend to mess things up in quite spectacular ways. Check the target function to make sure that it doesn&amp;#039;t store passed table.&lt;br /&gt;
&lt;br /&gt;
[[Category:HOWTOs|Use Tables Without Generating Extra Garbage]]&lt;/div&gt;</summary>
		<author><name>WoWWiki&gt;Rowaasr13</name></author>
	</entry>
</feed>