lua-users home
lua-l archive

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

> Does collectgarbage('count') report only the memory the Lua core allocated or would it contain memory that a C function allocated using malloc()?

Lua uses a user-supplied function for memory allocation, which may not be
malloc. If you (like most people) create a Lua state using luaL_newstate,
instead of lua_newstate then Lua will use realloc, which shares the same
pool as malloc.

If you want to allocate memory through Lua, call lua_getallocf to get the
current allocator. The protocol for using this allocator is explained in

Using lua_newuserdata is equivalent but much more convenient than
calling the allocator manually.

Note that all memory allocated through Lua (either manually or with
lua_newuserdata) is subject to gargabe collection, and so you need to
anchor it somewhere inside the Lua state.