~/talk

Memory Management in Python: Foundations, Problems, and Modern Techniques

Talkat PyCon India 2025 · 2025-09-12..09-15· [python]
slides:none on file

Explains CPython’s two-phase memory reclamation: reference counting plus generational GC with gen0 triggered after ~700 allocations and gen1 after ten gen0 collections, and PyMalloc versus OS malloc for small versus large objects. Shows concrete pitfalls — circular refs, mutable aliasing, unbounded containers, fetchall, logging.exc_info, and nondeterministic __del__ (use context managers instead) — and practical fixes like __slots__, generators, object reuse, capped deques or expiries. Demonstrates diagnostics with tracemalloc A/B snapshots and pympler summarize, finding 1.2 GB from 5,000 bytearrays in a WebSocket sessions leak.

AI-written summary · about

  1. 0:00Introduction and motivation
  2. 1:28Talk agenda overview
  3. 2:09Memory layout in programs
  4. 3:13Names objects and references
  5. 4:39Memory allocation basics
  6. 5:21Reference counting in Python
  7. 6:44Reference cycles and garbage collection
  8. 8:53Generational garbage collection
  9. 10:59Garbage collection thresholds
  10. 11:44Memory allocation demo
  11. 12:51Python vs OS memory allocators
  12. 15:23Common memory pitfalls
  13. 16:06Mutable aliasing issue
  14. 16:48Unbounded containers problem
  15. 18:20Batch processing for large data
  16. 18:44Exception logging memory trap
  17. 20:08Finalizer method limitations
  18. 21:55Debugging memory issues
  19. 22:16WebSocket memory leak case
  20. 23:22Using TraceMalloc tool
  21. 24:51Analyzing TraceMalloc output
  22. 26:40Pympler for object analysis
  23. 28:35Summary and Q&A
~/search
type to search 6,518 conferences, 143,918 speakers and 192,133 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.