Detect memory leaks of C extensions with psutil and psleak

New tool hunts sneaky Python add‑on leaks — cheers, then “AI vibes”

TLDR: psutil 7.2.0 and the new psleak tool let developers spot memory leaks hiding in native C add‑ons that normal Python counters miss. The crowd praised the practical win—especially Windows support—while one hot take accused the post of “AI vibes,” sparking a mini‑debate over tone versus utility.

Python’s leak hunters just got a new flashlight, and the comments lit up. psutil 7.2.0 now peeks under Python’s hood to spot memory leaks hiding in C add‑ons—the native code many popular packages use. The creator, grodola, dropped the release and a companion detector called psleak, plus a full explainer here. Devs swooned: tests will be updated, dashboards armed, leaks exposed.

The loudest applause? From Windows folks. One maintainer cheered that Windows is “underserved” for memory tools and plans to wire this into multiple projects. Another veteran chimed in with “thanks” and linked their own guide on writing C add‑ons that don’t leak—proof the community’s been waiting for a sharp, cross‑platform probe.

Then came the plot twist. A skeptic accused the announcement of reading “AI‑generated,” calling it soulless. Suddenly the thread split between “who cares, the tool slaps” and “writing quality matters.” It’s the internet: even a leak detector can’t plug the vibes discourse.

Under the drama, the pitch is simple: take a memory snapshot, run your code, take another. If the numbers climb, you’ve got a leak. There’s even a “tidy up” button to quiet background noise so the real culprits pop. Cue the memes about buckets and brooms—devs are ready to sweep.

Key Points

  • psutil 7.2.0 adds native heap introspection APIs (heap_info and heap_trim) to detect C-level memory leaks in Python environments.
  • heap_info reports allocator metrics: heap_used (small malloc), mmap_used (large malloc/mmap), and Windows-only heap_count (HeapCreate).
  • heap_trim attempts to free unused heap memory to reduce allocator noise, primarily for establishing measurement baselines.
  • Traditional metrics (RSS/VMS/USS, Python refcounts, GC stats) often fail to reveal leaks caused by C extensions due to allocator behavior.
  • A recommended workflow compares heap snapshots before and after repeated C extension calls; consistent increases indicate a native leak.

Hottest takes

“I have also released a new tool called psleak, which detects memory leaks in C extension modules” — grodola
“I really appreciate the support for Windows as that platform is currently underserved” — ofek
“The attached post feels AI-generated/AI-edited” — gortok
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.