lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

You should not rely on garbage collectors to free up any resource other than
memory - this holds true for Java, Smalltalk, .NET, Lua, or any other
garbage collected system. The problem is that you generally have no idea
WHEN your object will get collected - it'll happen when the collector needs
more RAM. Typically, system resources that you need collected are a lot
scarcer than memory, so you'll run out of resources long before you run out
of memory.

Granted, you can force lua to do a gc, but that'll have a performance

If, on the other hand, all you care about is preventing resource leaks, and
don't necessarily care when the cleanup happens, you can use the "gc" tag


-----Original Message-----
[]On Behalf Of Paul Hsieh
Sent: Monday, October 01, 2001 3:56 PM
To: Multiple recipients of list
Subject: User data garbage collection ...

I've discovered that userdata can be formed from a pointer to memory coming
either lua_newuserdata, or malloc/&static as usual.  Is the distinction
merely that
the first will be garbage collected (and luaM_free() will be called on it)
and the
second will not?

Even if that is so, how do I get a callback into my embedding program to
call the
"destructor" at the time of garbage collection for a userdata that I've
The objects I intend to create in my program will be numerous, and use a lot
system resources (including a seperate thread), so I need for them to be
whenever possible.

Is there something I am missing, or is Lua simply not a state where it can
solve my

Paul Hsieh