Dev Radar
Support
LiveUpdated 2026-11-05 23:17 UTC

How does free(ptr) in C know how much memory to release when you never pass it the…

How does free(ptr) in C know how much memory to release when you never pass it the allocation size? On glibc, malloc()…

This is a dev post classified by AGK Intelligence as Languages & runtimes (a tutorial), kept by the Dev Radar because it carries real work, not commentary.

How does free(ptr) in C know how much memory to release when you never pass it the allocation size? On glibc, malloc() keeps a hidden chunk header immediately before the pointer it returns. One word stores the chunk size, with the lowest three bits used as allocator flags. When you call free(ptr), glibc recovers that metadata. The size was never lost. It was simply hidden from your program. You can inspect the allocator’s usable size with the GNU-specific malloc_usable_size() function:

Posted by Strace (10.7k followers) 2 h ago · 22 likes · 617 views · view the original post on X. Kept by the Dev Radar as Languages & runtimes.

More dev work like this

Every post is read and classified by AGK Intelligence: what it is, which market it belongs to, and whether the link is a real tool. 31.8k posts from 5k X accounts over the last 21 days, 9.4k tools, 12 markets. New posts are collected several times an hour and the full ranking is recomputed every hour — last update 2026-11-05 23:17 UTC. Full method.