[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Garbage Collector Problem
- From: Richter, Jörg <Joerg.Richter@...>
- Date: Fri, 22 Aug 2014 10:55:23 +0000
I see very seldom a problem when running a large Lua application.
It is not reproducible and valgrind does not report anything. Let me show
the parts involved:
Lua side:
Timer( function() print "timeout" end ):start(1)
This call creates an (anonymous) timer object with a callback and calls a
member function start().
The Timer() function creates an userdata and stores the callback in a
weak-keyed table. The key is the Timer userdata, and the value is the
callback. The userdata is returned.
The start() function does a luaL_ref( LUA_REGISTRYINDEX ) of the
userdata to prevent that the userdata gets collected before the timeout
triggers.
When the timeout triggers, the userdata is retrieved with
lua_rawgeti(LUA_REGISTRYINDEX). Then the callback is retrieved by
looking up the userdata in the weak-keyed table.
The problem is that the callback is nil by then.
It seems that the userdata,callback pair was collected in between. But I was
unable to reproduce it even if I springle a lot of collectgarbage calls in the code.
My current assumption is, that the pair gets collected after the Timeout() function
ends and before the start() function begins. In this period of time there is no
strong reference from the registry to the userdata. But this would mean that the
register where the userdata is stored is not a strong reference. Can anybody deny
or confirm this?
- Jörg