[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: tables and the gc
- From: "Nick Trout" <nick@...>
- Date: Mon, 28 Apr 2003 10:51:23 -0700
AB> This example doesn't cut it for me. It is often the case when one
can not let Lua destroy objects in its own time due to system
interdependencies. If system A needs system B to manipulate data members
of A, clearly, by the time Lua decides to collect A, B may have long
gone. So, there must be a way to GC things on the spot in a fairly
straightforward and convenient fashion. What about weak keys and values?
Could they be of any help to the original poster? I have never used them
myself.
The example is not intended as a general solution to the resource
handling problem. It was a suggestion using the template provided by the
poster. I was making 2 points:
1) You could use the idiom:
function delete_object(x) return end -- returns nil
function classX:free() -- clean up explicitly
self.resource = delete_object(self.resource) -- deletes
resource and nils reference
end
2) Don't use GC to collect individual objects. It is very inefficient.
Garbage collection is not some magical functionality which will handle
all of your resources as well. It's purpose is to collect any unrequired
objects in as transparent a manner as possible. Most likely it's
operation will not fit your model for resource management.
Regards,
Nick