lua-users home
lua-l archive

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

> I've got a case where the memory occupied by a userdatum
> is not freed, even though Lua calls its __gc method.
> I'm failing to understand that, any help is appreciated!
> (Lua 5.1.2)
> [...]
> -- test.lua
> require "testlib"
> print("1:", collectgarbage"count") --> 22 KB
> print("2:", collectgarbage"count") --> 1046 KB
> collectgarbage"collect"
> print("3:", collectgarbage"count") --> 1044 KB

When a userdata has a __gc method, the first collection triggers the
finalizer, but the object is still alive (because the finalizer gets it
as a parameter, and may even resurect it). Only the next collection will
free the object. (Java has a similar behavior.)

-- Roberto