finds.dev← search

// the find

cloudwu/lua-snapshot

★ 531 · C · MIT · updated Aug 2024

Make a snapshot for lua state to detect memory leaks.

A C extension for Lua that snapshots the entire Lua state — every live object and its reference graph — so you can diff two snapshots and find what leaked between them. Aimed at game developers and server engineers running long-lived LuaJIT/Lua 5.x processes where memory growth is otherwise opaque.

The diffing approach is genuinely useful: take a snapshot before and after a suspected leak window, compare, and get exactly what's alive that wasn't before. The C implementation means it can walk the full GC graph including weak tables and upvalues that Lua-side introspection can't reach. cloudwu is the author of skynet, so this comes from real production use in high-throughput Lua server environments, not a toy. Single-file C with a Makefile — trivial to audit and embed.

The README is essentially empty; you're reading dump.lua to understand how to actually use it. No documentation on what the output format means or how to interpret the diff in non-obvious cases (cycles, weak references). No test suite at all. The last meaningful commit was years ago, and it only targets Lua 5.3/5.4 — LuaJIT compatibility is unconfirmed and likely requires patching. For anything beyond the happy path you're on your own.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →