lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi
 
Here is a little snippet of some code I have written recently, its working as I intended apart from the fact that I cant seem to free the large chunk of  memory I am using. I am clearly misunderstanding something about variable scope and garbage collection
 
I my main Lua file I have
 
local langSpecifier = 5 
local language = {}

if langSpecifier == 1 then
     language = require("english"
elseif langSpecifier == 5 then
     language = require("frenchBig")
end

 
frenchBig.lua looks like this
 
local french = {
 [1] = "This is French message 1",
 [2] = "This is French message 2",
 [3] = "This is French message 3",

......... snipped most of the 5000 rows for brevity here

 [5000] = "This is French message 5000", 
}
return french
 
 
then at the end of main.lua  I do this to free they big memory table as I am done with it

 print (string.format("Memory used at end = %.1f kbytes", collectgarbage("count")))
 
 language = nil   -- I was expecting this to free most of my memory
 
 collectgarbage("collect")
 print (string.format("Memory used at end after garbage collect = %.1f kbytes\r\n", collectgarbage("count")))
 
Output is
Memory used at end = 1314.4 kbytes
Memory used at end after garbage collect = 722.5 kbytes

normally my idle state memory usage for a minimal test script is about 90 kbytes.
 
So that big table in the require file is likely not being freed totally by the garbage collection. I don't understand why that is happening
 
Any thoughts or explanation would be appreciated
 
Thanks
 
Geoff