jacomyma [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=38310 Delete stuff to free RAM <p>Hi everyone,</p> <p>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?</p> <p>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:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>RAM: 0% FILL STATE WITH DATA... RAM: 41% DELETE STATE... RAM: 41%</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>The code:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>state = {} function _init() cls() print(&quot;ram: &quot;..flr(stat(0)/20.48)..&quot;%&quot;) print(&quot; fill state with data...&quot;) -- fill state with dumb data fill_state() -- test ram print(&quot;ram: &quot;..flr(stat(0)/20.48)..&quot;%&quot;) print(&quot; delete state...&quot;) state=nil print(&quot;ram: &quot;..flr(stat(0)/20.48)..&quot;%&quot;) end function fill_state() state.data = {} local str=&quot;&quot; for i=1,1000 do str=str..&quot;abcdefghijklmnopqrstuvwxyz&quot;..i end for i=1,100 do state.data[i] = {} for j=1,1000 do state.data[i][j] = str end end end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Isn't the garbage collector supposed to help me here? What did I miss? What is the way around the issue?<br /> Thanks :)</p> https://www.lexaloffle.com/bbs/?tid=34604 https://www.lexaloffle.com/bbs/?tid=34604 Sat, 29 Jun 2019 15:29:35 UTC