Quote:
I didn't know I could change the garbage collection thresholds.
I would advise you not to, the Lua manual suggests you can make things worse, I was just checking.
Thanks for your detailed response. You clearly have a problem, I am trying to narrow down what it might be.
I don't think it is the SetStatus part itself, nor the Lua script engine, per se. I ran this test in the Immediate (scripting) window on version 3.81, using Windows XP:
print ("memory usage before = ", collectgarbage ("count"))
hp = 4200
mana = 2200
move = 53
time = 1234
append_to_status = "the quick brown fox"
t1 = os.time ()
for i = 1, 500000 do
local status_line = hp .. " " .. mana .. " " .. move .. " " .. time .. " " .. append_to_status
SetStatus(status_line)
end -- loop
t2 = os.time ()
print ("time taken = ", t2-t1)
print ("memory usage after = ", collectgarbage ("count"))
This does 500,000 lots of the string concatenation you originally had (with the .. syntax) and then a SetStatus. I made up some figures, I presume they are similar to yours.
Looking at the XP task manager, these were my memory usage figures:
- Before opening the world = 7,100 Kb
- Before doing the SetStatus test = 8,556 Kb
- After doing the SetStatus = 9,184 Kb
First, I am confused about your reported figures, where you said you got the usage down to 10 Kb. I think you must mean 10 Mb. (1 Mb = 1000 Kb).
Even with no world open my copy uses 7,100 Kb (that is, over 7 Mb).
Opening a world seems to take up about 1.5 Mb, which seems OK to me. However after doing 500,000 SetStatus and Lua string concatenations, the memory only rises aby 0.5 Mb.
Plus, I checked the memory usage inside Lua by doing this:
/collectgarbage ("count")
My results were:
memory usage before = 83.6337890625
time taken = 8
memory usage after = 83.849609375
Thus the memory that Lua thinks it has used is only 0.2 Kb - hardly anything.
I think your memory consumption must be elsewhere, although I must admit I am puzzled as to why the operating system reports 500 Kb of usage, where Lua reports less than 1 Kb.
While I investigate this further, it might help if you can make a test script that reproduces the problem. Along the lines of what I have done above with SetStatus in a loop, you might try pushing a lot of data through one of your other script routines to see if you can find what is taking all the memory.
You mentioned the use of tables, it would be possible to consume a lot of memory if you did something like this:
t = {} --> make a table once
table.insert (t, "something") -- for each line from the MUD
If you were doing something like this then the table t would gradually get larger, and not be garbage-collected.