$30 off During Our Annual Pro Sale. View Details »
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
72
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
910
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
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.8k
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
6
2.2k
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
380
FluorTracer / RayTracingCamp11
kugimasa
0
230
認証・認可の基本を学ぼう後編
kouyuume
0
190
関数実行の裏側では何が起きているのか?
minop1205
1
690
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
160
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
130
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
500
ゲームの物理 剛体編
fadis
0
340
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
3
830
AWS CDKの推しポイントN選
akihisaikeda
1
240
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6k
Why Our Code Smells
bkeepers
PRO
340
57k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Building Applications with DynamoDB
mza
96
6.8k
Documentation Writing (for coders)
carmenintech
76
5.2k
Thoughts on Productivity
jonyablonski
73
5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
970
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
100
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
Optimizing for Happiness
mojombo
379
70k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
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?