Hello everyone,
I’ve encountered a question about the order and safety of __gc metamethod calls in Lua, and I’d like to confirm whether my usage is correct and what the best practice might be.
The attached document contains a simplified example.
When I run this code using `lua a.lua`, I get the following output:
It seems that the queue userdata’s __gc is invoked before xxx.__gc, even though the latter still references x inside its finalizer.
I’m wondering if I might be misunderstanding how __gc works.
If this behavior is expected, what would be the proper or recommended way to avoid such a situation?
Thank you very much for your time and help!