Skip to content
Preptima
hardConceptScenarioMidSeniorStaff

A long-running Python service keeps climbing in memory and never comes back down. How do you work out where the memory went?

5 min readUpdated 2026-08-15

Answer

Short answer

CPython frees an object the instant its reference count reaches zero, so steady growth is usually something still holding a reference rather than a leak. The cycle collector reclaims only reference cycles.

Was this answer helpful?

Likely follow-ups

  • What kinds of object does the cyclic collector track, and which ones can it ignore entirely?
  • How would you find what is still referencing an object you expected to be freed?
  • Why might tracemalloc show almost nothing while the process keeps growing?
  • When would you tune the generational collector's thresholds, or call gc.freeze before forking workers?

Related questions

Further reading