lua-users home
lua-l archive

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


On Sun, Apr 18, 2010 at 15:27, Henk Boom <henk@henk.ca> wrote:
> On 18 April 2010 11:18, Ralph Hempel <rhempel@bmts.com> wrote:
>> That was the missing piece. Just create a dummy string and set the one
>> and only metatable entry (__index) to nil allows the string library to
>> be garbagecollected and removed from my special weak-keyed _LOADED
>> registry table that I create in my main() before any of the standard
>> libraries are loaded.
>>
>> More importantly, it allows me to reload the string library when I
>> need to. Previous versions would not reload a library if it is already
>> in _LOADED because the old __index metamethod was preventing the
>> metatable from getting reclaimed.
>
> What happens if 'string' is re-loaded before the garbage collector
> runs, so that it is still in _LOADED?
>
>    henk
>

You could avoid that by doing collectgarbage("collect") immediately afterward.
I'm curious though why you didn't just clear the whole table, i.e.
setmetatable("a", nil)

-- 
Sent from my toaster.