[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: question: lua deterministic gc
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 23 Dec 2020 11:22:12 -0300
> I have been looking at how to manage/minimize memory usage in a C/Lua process/program running on Linux. I have observed some non-deterministic behavior with Lua’s collectgarbage() in “freeing” up memory for other processes to be able to use.
> Details may be found here:
> Specifically, is there a way to ensure all unused memory is freed from within Lua?
Calling 'collectgarbage' twice frees all memory not in use by Lua.
"Frees" here means to call 'free'; that does not ensure the memory is
returned to the OS and therefore is available to other processes.
That is all that can be done in ISO C.
Returning that free memory to the OS is a task to the memory allocator.
It probably depends on the memory fragmentation, specifically whether
the free memory forms blocks large enough to be returned. And
fragmentation depends on the pattern of memory allocations and, again,
on how the allocator behaves. All of this seems to be outside the
control of Lua.