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
84
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
960
Python Fest lightning talk
oinopion
0
93
Contributing to Django
oinopion
2
590
Django and Time Zones: New in the Trunk
oinopion
4
220
Other Decks in Programming
See All in Programming
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
1.9k
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
190
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
AI時代のUIはどこへ行く?その2!
yusukebe
21
7k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
170
Inside Stream API
skrb
1
680
Claspは野良GASの夢をみるか
takter00
0
180
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
500
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
180
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
110
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
610
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
160
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
Rails Girls Zürich Keynote
gr2m
96
14k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Everyday Curiosity
cassininazir
0
230
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
330
WENDY [Excerpt]
tessaabrams
11
38k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
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?