views:

302

answers:

1

I have a full userdata in Lua module written in C. The userdata has __gc() metamethod, which is called by garbage collector. Does lua interpreter free userdata memory after __gc() call, or do I have to free() it inside __gc()?

+4  A: 

You should not free the memory, as you didn't malloc() it yourself; Lua does both for you. In fact, the memory isn't even collected in the same garbage-collection cycle, as section 2.10.1 in the Lua 5.1 reference manual explains.

Jan de Vos