View Single Post
08-25-13, 04:02 AM   #14
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Originally Posted by myrroddin View Post
To illustrate:
Lua Code:
  1. for i = 1, 5 do
  2.     -- all iterations
  3.     local var = "dog"
  4.     print(var)
  5. end
  6.  
  7. -- var never needs to be changed
  8. local var = "dog"
  9. for i = 1, 5 do
  10.     print(var)
  11. end
In the first example, you create five times the amount of garbage collected compared to the second.
This is why I can't quite figure out the general statement "define variables in the lowest scope possible"
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote