[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Strange garbage collection problems
- From: "Thomas Harning Jr." <harningt@...>
- Date: Tue, 24 Oct 2006 13:18:15 -0400
I've been writing a proxy using libevnet. It uses 1-to-1 callbacks
when requests are fulfilled.
Example use in lua:
lua_evnet:connect(function(sock, err)
if not sock then error(err) end
sock:readline(function(_sock, dataOrErr, closed)
if not _sock then error(dataOrErr) end
print(dataOrErr)
if closed then
print(_sock, "closed")
end
_sock:close()
end)
end)
lua_evnet.eventloop()
In order to handle the callbacks, I use luaL_ref(L, LUA_REGISTRYINDEX,
XXX) to create integer references to the socket object and the
callback function.
When the callback is raised in C, the references are pulled and
removed from the registry and used to continue things.
However... I'm discovering that somehow the socket objects are
occasionally being collected in between initiating a readline and the
callback function... however... the callback function still receives
the reference (containing the same pointer data/etc before it was
collected) causing valgrind to complain [as it rightly should].
The userdata is allocated w/ tolua++ storing the pointer inside the
userdata object.
Should the garbage collector _not_ call the __gc method if there's
still a reference sitting in the registry?
At the moment I can't post up testable code.
Any ideas???
--
Thomas Harning Jr.