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
Tomek Paczkowski
November 28, 2013
Programming
0
74
Python Memory Management
A simple talk about simple problems with Python memory allocator
Tomek Paczkowski
November 28, 2013
Tweet
Share
More Decks by Tomek Paczkowski
See All by Tomek Paczkowski
Dispelling py.test magic
oinopion
0
920
Python Fest lightning talk
oinopion
0
91
Contributing to Django
oinopion
2
570
Django and Time Zones: New in the Trunk
oinopion
4
210
Other Decks in Programming
See All in Programming
クラウドに依存しないS3を使った開発術
simesaba80
0
180
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.4k
Java 25, Nuevas características
czelabueno
0
120
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
510
Claude Codeの「Compacting Conversation」を体感50%減! CLAUDE.md + 8 Skills で挑むコンテキスト管理術
kmurahama
1
660
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
150
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
540
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
200
GoLab2025 Recap
kuro_kurorrr
0
780
Python札幌 LT資料
t3tra
7
1.1k
Graviton と Nitro と私
maroon1st
0
140
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
180
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
67
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
140
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
34
End of SEO as We Know It (SMX Advanced Version)
ipullrank
2
3.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
0
46
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
520
The agentic SEO stack - context over prompts
schlessera
0
570
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
99
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
79
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
590
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?