Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Python Memory Management
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Tomek Paczkowski
November 28, 2013
Programming
75
0
Share
Python Memory Management
A simple talk about simple problems with Python memory allocator
Tomek Paczkowski
November 28, 2013
More Decks by Tomek Paczkowski
See All by Tomek Paczkowski
Dispelling py.test magic
oinopion
0
940
Python Fest lightning talk
oinopion
0
91
Contributing to Django
oinopion
2
580
Django and Time Zones: New in the Trunk
oinopion
4
210
Other Decks in Programming
See All in Programming
AIエージェントで業務改善してみた
taku271
0
180
forteeの改修から振り返るPHPerKaigi 2026
muno92
PRO
3
210
AI-DLC 入門 〜AIコーディングの本質は「コード」ではなく「構造」〜 / Introduction to AI-DLC: The Essence of AI Coding Is Not “Code” but “Structure”
seike460
PRO
0
210
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
120
おれのAgentic Coding 2026/03
tsukasagr
1
130
野球解説AI Agentを開発してみた - 2026/02/27 LayerX社内LT会資料
shinyorke
PRO
0
390
条件判定に名前、つけてますか? #phperkaigi #c
77web
2
940
AI活用のコスパを最大化する方法
ochtum
0
370
PHPで TLSのプロトコルを実装してみるをもう一度しゃべりたい
higaki_program
0
170
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
120
感情を設計する
ichimichi
3
460
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
260
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Limits of Empathy - UXLibs8
cassininazir
1
280
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
670
Between Models and Reality
mayunak
3
260
Design in an AI World
tapps
0
190
Scaling GitHub
holman
464
140k
The Spectacular Lies of Maps
axbom
PRO
1
680
Designing for humans not robots
tammielis
254
26k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
The Pragmatic Product Professional
lauravandoore
37
7.2k
Become a Pro
speakerdeck
PRO
31
5.9k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Transcript
Python Memory Management Tomasz Paczkowski Pykonik, 28.11.2013
Case Study • Long lived web process • Periodically allocates
boatloads of memory • Never releases it
Distilled code def main():! big = alloc(100000)! small = alloc(1)!
del big! # memory not released
[Demo time]
Diagnose: Memory Fragmentation big small small big
Solution • Make better use of memory • Subprocess •
jemalloc* via LD_PRELOAD
Fun with Python allocator • Python does not use malloc
directly — too costly for small objects • Instead implements more sophisticated allocator on top of malloc
Pools for integers ints = range(5*1000*1000)! del ints! import gc;
gc.collect(2)
Free lists • For handful of most common types Python
keeps unused objects in so called free lists • Those are most significantly: lists, dictionaries, frames • Speeds up code execution immensely
[Demo time]
Conclusions • Sometimes memory leak is not what it seems
• glibc malloc is not the best of breed • do memory intensive work in subprocess • be mindful when using C extensions
Thanks. Questions?