Python 'Memory Leak' Turned Out to Be a Faulty RSS Measurement Method
A developer building a RAG knowledge base pipeline repeatedly saw memory usage warnings that caused the process to abort, leading to suspicion of a memory leak in the embedding loop. The culprit turned out to be Python's ru_maxrss metric, which records peak memory usage since process start rather than current usage, so the value never decreases even after memory is freed. Switching to Linux's VmRSS value from /proc/self/status revealed that memory was actually stable around 1.8GB after model load, with no leak present. A second compounding error was setting a 1GB RSS limit without first measuring the post-model-load baseline, which alone consumed roughly 1.6GB. The developer also improved pipeline efficiency by switching from per-chunk to batched model encoding, processing 50 chunks at a time.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in