lua-users home
lua-l archive

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


Dean Sellers wrote:
> If I traverse 'bigtab' it is empty, as expected and 'print(gcinfo())'
> reports 20-30k of memory in use. Then if I do 'bigtab={};
> collectgarbage(); print(gcinfo())' the Lua shell reports that it is only
> using a minimal amount of memory again but there is around 40Mb of RAM
> still held by the Lua shell reported by top. Once I exit the shell this
> is released, but it looks as though the allocator (or GC) has leaked a
> pile of memory.
> 
> I have read the Pil section on the allocator and done some tests on the
> embedded system to make sure that realloc(ptr, val) works as you would
> expect, and it appears to. So before I dig too much further I thought I
> would ask if anyone can shed any light on why this might be happening.

To my knowledge that is the default behaviour of malloc/free
(independent of Lua). malloc requests new memory from the kernel but
free doesn't return it to the kernel -- instead it is reused by the same
application when malloc is called later. In usual cases this is way
faster than calling the kernel for every single structure -- if that is
even possible at all and the kernel doesn't send entire pages anyway.

Best regards,

David Kolf