Thread Tools Display Modes
08/06/14, 10:50 AM   #1
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
LUA Memory Limit

Someone in my guild ran a diff of UserSettings.txt and noticed there is now a line for LUA memory limit:

Code:
SET LuaMemoryLimitMB "64"
Has anyone run into any issues yet or seen how close to the limit they're running?

For a rough estimate, my personal SavedVars folder is running around 10.5MB and 14MB in the addons folder. Most data-heavy addons seem to either pre-define the data (map pins) or pull and store the data in SavedVars (inventory, character info, guildmate info), so adding those would be a decent estimate.

EDIT: For an actual count, you can use this (or a variation):
Lua Code:
  1. /script d(math.ceil(collectgarbage("count")).." KB")

Last edited by Sasky : 08/07/14 at 02:57 AM.
  Reply With Quote
08/06/14, 10:56 AM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
My saved variables folder is 52.4MB (the biggest is PriceTracker.lua with 34.1MB) and no error so far.

By the way there is a new event:
EVENT_LUA_LOW_MEMORY

and when it occurs, it shows this error message:
"Lua is reaching its memory limit. You should consider disabling some addons and reloading the UI."
  Reply With Quote
08/06/14, 01:08 PM   #3
Deome
 
Deome's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 29
Lightbulb

Now that is very handy news to have--I'm always worrying about memory.

Especially the event. Now I can use the event to add a function that provides players with a little more information, like "Hey, take a screenshot and post this in a bug report for DD! I want to know if you see this!"
  Reply With Quote
08/06/14, 02:41 PM   #4
Harbonah
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1
Originally Posted by Garkin View Post
My saved variables folder is 52.4MB (the biggest is PriceTracker.lua with 34.1MB) and no error so far.
Just for information

Addon folder 33MB (96 addon)
Savedvariables folder 24MB

On main char ~85 addon active, no error
On alts ~85 addon active, always get the error
On mules 40-50 addon active, no error
  Reply With Quote
08/06/14, 07:56 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
o.O In WoW, it's not unheard of to have memory usage of over 150MB.
  Reply With Quote
08/06/14, 08:26 PM   #6
mctaylor
 
mctaylor's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 21
Originally Posted by Garkin View Post
[...]
new event: EVENT_LUA_LOW_MEMORY

and when it occurs, it shows this error message:
"Lua is reaching its memory limit. You should consider disabling some addons and reloading the UI."
I'm assuming even well-behaved add-ons aren't expected to listen and effectively reaction to this event?

With Lua's garbage collection, can you free much memory usage from within an add-on? Free up a few tables by setting them to nil? Set any textures to nil or unload otherwise free them?

I don't know if an add-on can disable or free itself.

I guess you can un-register for events, or even set functions to nil but I don't thing that's enough to kill an add-on in memory. (Functions being a first-class data type / object)

Not intended to be dismissive of Lua or the versatility of automatic GC. Just surprised to see it, but I'd guess its visible unintentionally because it is part of the Add-on API / support.
  Reply With Quote
08/06/14, 10:25 PM   #7
Rainith
Join Date: Apr 2014
Posts: 5
So I'm getting this every time I log in, can I change the setting in the UserSettings file to a bigger number to make it go away? If so is there some sort of upper limit number that I shouldn't set it above?
  Reply With Quote
08/06/14, 10:40 PM   #8
katkat42
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 155
Originally Posted by Rainith View Post
So I'm getting this every time I log in, can I change the setting in the UserSettings file to a bigger number to make it go away?
It seems likely, and worth a try if you're getting errors.

If so is there some sort of upper limit number that I shouldn't set it above?
I imagine that varies with the power of your computer. If you've got lots of RAM to spare and don't run a lot of stuff in the background, you probably have a lot of leeway. But if it were me, I would probably stick to powers of 2 (ie, 128, 256...).
  Reply With Quote
08/07/14, 02:56 AM   #9
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Originally Posted by Rainith View Post
So I'm getting this every time I log in, can I change the setting in the UserSettings file to a bigger number to make it go away? If so is there some sort of upper limit number that I shouldn't set it above?
Yeah, it depends on how much system memory you have. You probably don't want to push it to say the 4GB range if you have 8GB of RAM.

Also, how many addons are you running? This could just be because you use a lot of addons (which adds up) or could be from a couple that just use a lot of RAM.

PS: To see how much RAM you're actually using, you can enter this command in the chatbox:
Lua Code:
  1. /script d(math.ceil(collectgarbage("count")).." KB")
  Reply With Quote
08/08/14, 08:22 PM   #10
Rainith
Join Date: Apr 2014
Posts: 5
Just as a follow up, I checked and I'm currently using about 74 megs, so 10 or so over the default limit. I went ahead and edited that line in the UserSettings file and doubled it to 128. It stopped the message popup every time I logged in or reloaded the ui. Nothing negative noticed as of yet.
  Reply With Quote
08/09/14, 11:28 AM   #11
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Originally Posted by Rainith View Post
Just as a follow up, I checked and I'm currently using about 74 megs, so 10 or so over the default limit. I went ahead and edited that line in the UserSettings file and doubled it to 128. It stopped the message popup every time I logged in or reloaded the ui. Nothing negative noticed as of yet.
You probably won't unless you force the system to go to page swap. That will probably only occur if an addon has a memory leak. In fact, I'd bet they put this in to cover their bases and make sure addons aren't causing memory leaks. (Even though you have to have rather bad design to do in a language like LUA, since it does automatic garbage collection.)
  Reply With Quote
08/09/14, 05:11 PM   #12
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by mctaylor View Post
I'm assuming even well-behaved add-ons aren't expected to listen and effectively reaction to this event?

With Lua's garbage collection, can you free much memory usage from within an add-on? Free up a few tables by setting them to nil? Set any textures to nil or unload otherwise free them?
The best you can do for memory management is to use weak table references where appropirate (cachign scenarios):
http://www.lua.org/pil/17.html

That way the GC can decide to throw it out when it needs memory, but it stays around if no collection is neesesary.
And generally the GC should have tried to collect everything possible before it runs into a OOM exception.
The most reliable way to use a weak reference is to assign it's value to a local variable.
If the item was already collected, you get nil. If not, you now have a strong reference (for the duration of your code).

I used a weak reference table for the cache in LibConstantMapper. If the GC needs the memory, it can collect it any time. If not, it keeps the calls up to speed.
  Reply With Quote
08/09/14, 05:20 PM   #13
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by Sasky View Post
Yeah, it depends on how much system memory you have. You probably don't want to push it to say the 4GB range if you have 8GB of RAM.
Note quite true. The game itself is still a 32 bit application so it cannot use more the 4 GiB memory, regardless how much the computer has.
This lua memory limit (propably) only says how much of those 4 GiB can be taken up by Lua (and thus addons).
If you set it too high, addons might take too much memory and then there is not enough for the graphics and game left (so game OOM exception might become more common). Raise it carefully and ideally by multiplying the original value by 2.
  Reply With Quote
08/18/14, 08:33 AM   #14
TotterTates
Join Date: Apr 2014
Posts: 1
Originally Posted by zgrssd View Post
The best you can do for memory management is to use weak table references where appropirate (cachign scenarios):
http://www.lua.org/pil/17.html

That way the GC can decide to throw it out when it needs memory, but it stays around if no collection is neesesary.
And generally the GC should have tried to collect everything possible before it runs into a OOM exception.
The most reliable way to use a weak reference is to assign it's value to a local variable.
If the item was already collected, you get nil. If not, you now have a strong reference (for the duration of your code).

I used a weak reference table for the cache in LibConstantMapper. If the GC needs the memory, it can collect it any time. If not, it keeps the calls up to speed.
I can build a computer and customize pieces of hardware like nobody's business, but when it comes to writing code I'm completely lost. Could I trouble you to assist with adding these tables to my files?
  Reply With Quote
12/18/14, 12:52 AM   #15
recreare
Join Date: Dec 2014
Posts: 1
I set my LUA memory from 64 to 128 as I saw here, and I save the file, but it seems to keep setting itself back to 64. Any similar experiences/suggestions?
  Reply With Quote
12/18/14, 04:15 AM   #16
igerup
 
igerup's Avatar
Join Date: Sep 2014
Posts: 5
Don't forget to set the file properties to read only after you've made the changes you want.
  Reply With Quote
12/18/14, 06:47 AM   #17
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by recreare View Post
I set my LUA memory from 64 to 128 as I saw here, and I save the file, but it seems to keep setting itself back to 64. Any similar experiences/suggestions?
If you want to make changes to the UserSettings.txt, you have to do it when game is not running.

It's because game reads settings from the file only during the startup. But settings are saved from memory to the file everytime when you logout to the character selection screen, to the account login and finally when game is closed. In other words if you've made any changes to the settings when game is running, it will be automatically overwritten with the settings currently in use.

If you want to change Lua memory limit value when game is running, type the following command to the chat:
Code:
/script SetCVar("LuaMemoryLimitMB", "128")


Originally Posted by igerup View Post
Don't forget to set the file properties to read only after you've made the changes you want.
I do not recommend making UserSettings.txt read only.

Last edited by Garkin : 12/18/14 at 06:50 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » LUA Memory Limit


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off