As @siffiejoe notes in the comments, the Lua helper library uses the βfreelistβ mechanism to track free index holes, and this list is never compressed, i.e. its size is always equal to the peak distribution - this is the ratio of price and speed, you can check the implementation to determine the basic logic.
If you are sure that there are no active links in the registry, you can clear the whole keys manually (see the note below). If you want a completely empty registry, then lua_newtable(L), lua_replace(L, LUA_REGISTRYINDEX)
will do this. This is not a good idea - see the comments below this answer.
(Note that you probably can't just check if all refs links were balanced, because some code might refer to an integer value. Maybe I'm wrong.)
source share