[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Tolua memory leak?
- From: awheeler@...
- Date: Wed, 02 May 2001 05:23:32 -0000
Hey folks,
I'm using the tolua alpha (?) with lua v4.x and seem to be running
into a memory leak. I've built a package for class Foo: a simple
class that has two member-functions as well as a simple constructor
and destructor. I built a binary file that executes the following
script:
oFoo = Foo:new()
oFoo:delete()
When the script finishes, the program exits - and the debugger
reports a memory leak.
I've tracked the memory-leak down to a synchro issue with lua_close()
and tolua's userdata garbage-collection tag-method. Here is what
seems to be going on:
1. lua_close() calls collect_userdata(). This function strips
the "udt" list/table of all its userdata objects, and moves them to
a "collected" hash-table. The function then returns.
2. lua_close() then calls something like collectgcTM(), which
iterates through the list of collected userdata objects and executes
any gc tag-method for any object that has a gc tag-method.
3. an object pointing to the address of my now-deleted oFoo object
has a gc tag-method, so its tag-method is executed. Tolua has set
the tag-method to something like instance_gc().
4. instance_gc() calls toluaI_undo_clone().
5. toluaI_undo_clone() calls push_userdata() to push a pointer to the
clone onto the Lua stack. push_userdata() ultimately instantiates a
new userdata object entry - and puts it on the udt list (!).
6. toluaI_undo_clone() ultimately returns, and collectgcTM()
ultimately returns, too, while the userdata object remains on the udt
list...
7. tolua_close() finally returns: but it never goes back and re-
cleans up the udt list. Hence the userdata object created during the
gc tag-method's call to push_userdata() never gets cleaned up.
Is this a known problem? Can anyone else verify the above sequence
of events? It seems that I could just call collect_userdata() right
after collect_gcTM() and this would solve the problem: but it's, of
course, a fairly nasty hack. Otherwise I don't yet see a nice way to
solve this problem.
Any thoughts?
Thanks for any help,
-andrew