lua-users home
lua-l archive

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


A simplistic approach to garbage collection for temporaries. This is a
simplified version of the zero-reference-count table optimization for
reference counting.

* For each stack (i.e., state/thread), maintain a table of every object (or
every user data object) that gets created.

* Whenever an object is stored into a table or is copied from thread to
thread, set a "heap" mark flag on the object.

* When the creation table is full or at program request

    - Scan the stack:
        For any objects referenced from the stack, set a stack mark flag
        on the object

    - Scan the table:
        For any object with the heap flag set, remove it from the table
        For any object without the heap flag but with the stack flag,
            clear the stack flag and leave it in the table
        For any object with neither flag, it is now garbage and can
            be collected

This is essentially a very simplistic generational GC that maintains a
generation of objects that are only referenced from the stack of a single
thread. It doesn't do much for complex data structures, but it ought to be
pretty good for collecting simplistic temporaries. The design optimization
point here is to limit the "reference counting" work to a few relatively
rare operations -- in this case storing an object into a table or copying it
between threads.

Even with this, another issue with creating lots of temporary objects is
probably going to be making allocation and collection fast.

Mark