tracemalloc.get_traced_memory() reported 9,457 B per compiled 500-item $in rule on Python 3.14.5 . Calling macOS malloc_zone_statistics around the same 1,000-instance loop reported 142,317 B per instance, 15x more RAM than Python admitted existed.
In Ruby 4.0.5 wrapping the same C99 library, ObjectSpace.memsize_of reported only one wrapper slot while hiding over 137 KB of native heap. Built-in VM profilers stay blind to C heap unless both your benchmark and your extension cross the allocator boundary.
Why Python and Ruby miss C heap
Python's tracemalloc hooks PYMEM_DOMAIN_RAW , PYMEM_DOMAIN_MEM , and PYMEM_DOMAIN_OBJ ( PyObject_* and PyMem_* ). Direct libc malloc or calloc calls inside a wrapped C library skip all three hooks, leaving only the thin Python shell visible.
Ruby's GC.stat counts Ruby RVALUE slots. ObjectSpace.memsize_of(obj) includes native C allocations only when rb_data_type_t.function.dsize is implemented.…