[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: When are coroutines collected?
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Wed, 27 Feb 2008 10:27:33 -0500
Chris wrote:
> Consider the following:
>
> run = {}
> for i=1, 100000 do table.insert(run, coroutine.create(function()
> end)) end print(coroutine.status(run[1]))
> for k,v in ipairs(run) do coroutine.resume(v) end
> print(coroutine.status(run[1]))
> run = {}
> collectgarbage("collect")
>
> At the end all the coroutines are "dead" yet they are still taking up
> memory. It looks like they have not been collected. Is there some
> sort of weird table interaction here or something else that must be
> done to get rid of them from memory? As it stands now my application
> just continues to increase its memory usage over time as coroutines
> are created and destroyed. Eventually it eats all the memory on the
> machine.
I tested the above code on my machine, a modern x86 PC, with 32bits
Windows XP and a custom "unpatched" Lua build, only adding a io.read"*l"
before and after collectgarbage. Prior to garbage collection, the
process uses 110MB, just after the collectgarbage call that is down to
under 2MB.
Is your problem happenning with the exact code above (including the
collectgarbage call) ? Or are you wondering why the collectgarbage is
necessary ?