[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Garbage collection does not mean releasing memory
- From: Mark Hamburg <mhamburg.ml@...>
- Date: Thu, 4 Jun 2015 14:02:32 -0700
As I understand it, erasing never causes a structure to get smaller. I forget which operations will cause a structure to compact.
Mark
> On Jun 4, 2015, at 12:56 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>
> If you create a sequence with length 2^n, erase all the elements
> except those with keys 1,2,4,8,16,...,2^n, and call collectgarbage(),
> Lua does not release the memory.
>
> n=20; t={}; for k=1,2^n do t[k]=k end
> for k=1,#t do if math.log(k,2)%1 ~=0 then t[k]=nil end end
> print("memory in use before 'collectgarbage()': "..(collectgarbage"count"))
> collectgarbage()
> print("memory in use after 'collectgarbage()': "..(collectgarbage"count"))
>
> Output:
>
> memory in use before 'collectgarbage()': 16409.73828125
> memory in use after 'collectgarbage()': 16406.772460938
>
> There's probably some subtlety I don't understand.
>