lua-users home
lua-l archive

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


Ignacio Castaño:
> I'm just wondering in which order are objects garbage collected on
> shutdown.

Acording to the Lua5 manual (Lua4 is similar):
    "In a garbage-collection cycle, the finalizers for userdata are called
     in reverse order of their creation, that is, the first finalizer to be
     called is the one associated with the last userdata created in the
     program (among those to be collected in the same cycle). "

If that order was not acceptible (perhaps you have stored some forward links
in the earlier created data) then you would have to keep extra links to the
later data (to prevent it from being GCed while the earlier data still
referenced it), and when the earlier data was GCed it would release those
links (and then rely on a later GC to collect the data). Not all that
pretty, really.

*cheers*
Peter Hill.