[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Garbage Collection
- From: Diego Fernandes Nehab <diego@...>
- Date: Tue, 30 Jul 2002 03:17:04 -0300 (BRT)
Hi,
> I wish to ensure that all handles are closed and all memory
> is deallocated when lua_close is called. I also want the
> lua garbage collection to close any loose statement(cursor)
> handles. However, I dont want statement handles closed when
> I am fetching data from them.
This is something I was about to start working with. What you need is to
keep a reference to the statement in every cursor created by it.
Probably the best solution is to do it within the C code. There was
supposed to be code in LuaSQL to do this.
> Finally, the following two C code fragments are used in luaSQL,
> which approach is better?
I prefer the lua_newuserdata. Lua itself frees the memory in that case.
All you need to do is clean up whatever objects you initialized in the
memory space returned by the function.
> lua_pushusertag(L, conn, env->conn_tag);
> cursor->conn = lua_ref(L, 1);
> /* gc method closes handle, does lua_unref(L, cursor->conn);
> and presumably relies on gc to clean up the cursor userdata */
See the code above? The reference ensures that the connection object
will not be GCed before the cursor object is GCed. Is this not working?
Best regards,
Diego.