Johnson Lin wrote: > And there's a lot of callbacks I am allocating in the UI. At least > dozens per menu. So when GC is not collecting for a while, it still > hits the FFI callback limit in the LuaJIT. You can raise the limit by changing LJ_NUM_CBPAGE in lj_def.h. But this is only delaying the inevitable ... [ The key problem always arises when there are different resources with different scarcity with dependencies on each other. The GC only reacts to memory pressure -- it doesn't even see the callback slots. It sees the allocated function pointer objects, but they take up only a couple of bytes each. If you need a stable minimum of (say) 1 MB of memory after the initial growth phase, then the GC will schedule its work to keep the maximum memory below 2 MB. So if you try to allocate 1000 callback slots the GC will hardly take notice. OTOH always scheduling a GC when the slots run out is a bad idea. And the incremental GC would need to run at a pretty fast pace, which makes it mostly non-incremental wrt. pause times. ] IMHO scarce resources cannot easily be managed by a non-refcounting GC -- it's not designed to do that. If you don't want to resort to fully manual management, then RAII or other scope-based approaches are your best bet. --Mike