lua-users home
lua-l archive

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


On Mon, Jun 27, 2011 at 11:26 AM, Gaspard Bucher <gaspard@teti.ch> wrote:
>
>
> On Mon, Jun 27, 2011 at 11:29 AM, Jerome Vuarand <jerome.vuarand@gmail.com>
> wrote:
>>
>> 2011/6/27 steve donovan <steve.j.donovan@gmail.com>:
>> > On Mon, Jun 27, 2011 at 11:08 AM, Gaspard Bucher <gaspard@teti.ch>
>> > wrote:
>> >> collectgarbage() ---- does not collect old "foo". Why ? Where is it
>> >> stored ?
>> >> print('end') -- the garbage collection after 'end' removes old "foo".
>> >
>> > It's still there, as a global of the original environment.
>>
>> But the original environment is unreachable (except by the gc_mt.__gc
>> function itself), and it should be collected.
>>
>
> Yes, this was my concern: I thought the original _ENV was unreachable but it
> is not: since "foo" is not garbage collected, it must be reachable from
> somewhere (which means the original _ENV is also reachable). Therefore, the
> question is from where is old _ENV reachable and why ?
> Gaspard

Doing the following before clearing _ENV will do the trick:

do
  local reg = require"debug".getregistry()
  reg._LOADED._G = nil
  reg[2] = {tostring = tostring} -- for print()
end