Hi everyone,
I am tinkering with procedural generation and I inevitably run out of memory. I expected to be able to delete some obsolete data to free some memory but I do not succeed. It looks like deleting variables does not free RAM. What did I miss?
I isolated that in the following script that just fill a global variable named STATE with random data, then set it to NIL, and track that it does not free any RAM. It outputs as such:
RAM: 0% FILL STATE WITH DATA... RAM: 41% DELETE STATE... RAM: 41% |
The code:
state = {} function _init() cls() print("ram: "..flr(stat(0)/20.48).."%") print(" fill state with data...") -- fill state with dumb data fill_state() -- test ram print("ram: "..flr(stat(0)/20.48).."%") print(" delete state...") state=nil print("ram: "..flr(stat(0)/20.48).."%") end function fill_state() state.data = {} local str="" for i=1,1000 do str=str.."abcdefghijklmnopqrstuvwxyz"..i end for i=1,100 do state.data[i] = {} for j=1,1000 do state.data[i][j] = str end end end |
Isn't the garbage collector supposed to help me here? What did I miss? What is the way around the issue?
Thanks :)
P#65465 2019-06-29 15:29