lua-users home
lua-l archive

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

> IIRC the number of cycles necessary depends on the depth of the data
> to collect. For example
>   t={}
>   t=nil
> will require one cycle, while
>   t = { t = { t = { t = { t = { t = {} } } } } }
> will require 6 cycles.

That is not true, unless the program uses weak tables. Otherwise a table
like the one above should be collected in one cycle.

There are three things that may "delay" the release of all available
memory. One is weak tables.  Another is finalizers: a userdata with
a __gc metamethod cannot be collected in the same cycle that runs
its finalizer. The third is some internal arrays, such as stacks and
buffers. When they are too big, the collector shrinks them by some fixed
factor (e.g., it may halve the original size). So, if they are really
big, it may take some cycles for them to shrink to a size that the
collector will not shrink anymore.

Probably what is happening in that program is this: when Lua reads
that huge string, an internal buffer grows to accomodate that string.
After that, it takes some collections for the buffer to resize to
a reasonable size again.

-- Roberto