lua-users home
lua-l archive

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

Title: Help with lua 5.1 strange allocation behaviour

Hello listers,

I am in the process of embedding Lua into an embedded device. As part of this I started to play around with doing things that a user might do, just to see what would happen. I noticed a strange thing which I am hoping someone out there might be able to explain. I am using Lua 5.1.5 on an ARM device with MMU running a linux kernel and the uClibc c libraries.

At the moment I have just compiled Lua on the cross toolchain. This all works fine and the tests in the test directory all run. The system I am moving this from was a NOMMU system so memory fragmentation and use was important, so out of curiosity mainly I started to investigate what would happen to the larger system if a user did something like;

for i=1,math.huge do bigtab[{}]=i end

Of course you get an out of memory eventually in the Lua shell. Then I thought I would do the following;

bigtab=setmetatable({}, {__mode="k"})
for i=1,math.huge do bigtab[{}]=i end

On my host system, Ubuntu VM with 1G of RAM it runs <forever> without increasing memory use. On the embedded target I get the same out of memory message eventually, which surprised me. Also top reports that the Lua process is holding around 40M of memory.

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.

Thanks in advance,


__________ Information from ESET NOD32 Antivirus, version of virus signature database 7127 (20120510) __________

The message was checked by ESET NOD32 Antivirus.