lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris wrote:
[...]
> Right, that is what is strange.  If I look at the raw memory usage of
> the process (running Linux here) it's still using all the memory even
> though everything has supposedly been collected.  In my real test I
> add a "socket.sleep" to the end so I can have a chance to check the
> memory usage in the OS.  I also create about 1 million coroutines
> which use about 1.3 GB of RAM, after the collection the process it is
> still using 1.3 GB of RAM.

With Lua 5.2 and a million coroutines I see about 800MB.

*However*, if I stick your script in a function, and run it twice from
the same Lua session, I *still* see about 800MB, so the memory isn't
being leaked --- it's merely not being released back to the system.

This is fairly normal behaviour although naturally a bit undesirable.
It's easy for a libc to extend its heap with brk(). It's much harder for
it to shrink its heap again. glibc tries fairly hard, allocating big
blocks with mmap() so that it can release them again when freed, but if
Lua is allocating structures to small to trigger that it'll still gobble
lots of space with brk() instead.

Not sure what you can do about this, but you may not have to. Provided
you're not using space required by other processes, the Lua session will
reuse all that memory and it won't be wasted.

- --
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Wizards get cranky, / Dark days dawn, / Riders smell manky, / The
│ road goes on. / Omens are lowering, / Elves go West; / The Shire needs
│ scouring, / You may as well quest." - John M. Ford
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHxYcLf9E0noFvlzgRAmwjAJ9E08+8QDL9DMpfD3UJTf2qxFqT0gCgmHWG
ndI3Wlt8/yzb5rYGXSGEb6U=
=uV4u
-----END PGP SIGNATURE-----