|
They are garbage collected. Roberto did an interesting paper a while back on how Lua handles upvalues. As I recall it, they start on the stack and are migrated out of the stack when the declaring function (not referencing function) goes out of scope. So when your outer function returns, they logically move from the stack to the heap. Remember, though, that things on the stack can be GCed too; in languages like Lua the distinction between the stack and heap is less clear-cut that C or C++.