TrackLeak

A memory leak detector for Python applications that hooks directly into the allocator.


The Problem

Debugging memory leaks in production Python apps is painful. Traditional profilers like tracemalloc add overhead and miss C-extension allocations entirely. When your Python process is slowly eating memory in production, you need something that works without restarting the process and without adding instrumentation code.

How It Works

TrackLeak intercepts both standard malloc and Python’s PyMem_* functions using LD_PRELOAD. It walks the Python stack to identify the source of each allocation and tracks which allocations never get freed.

The result: a clear report showing exactly which functions are retaining memory — with file paths, line numbers, and retention percentages.

Features

  • zero instrumentation no code changes needed in your application
  • live processes works on already-running processes
  • C-extension aware catches leaks that tracemalloc misses
  • minimal overhead designed for production use
  • detailed output file paths, line numbers, retention percentages

Stack

  • language C, Python
  • technique LD_PRELOAD · malloc hook · PyMem_* interception


Copyright 2026 Deepanshu Kartikey, all rights reserved — kartikey406@gmail.com