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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Tomek Paczkowski
November 28, 2013
Programming
0
75
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
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
メタプログラミングで実現する「コードを仕様にする」仕組み/nikkei-tech-talk43
nikkei_engineer_recruiting
0
210
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
320
仕様漏れ実装漏れをなくすトレーサビリティAI基盤のご紹介
orgachem
PRO
7
3.1k
20260320登壇資料
pharct
0
120
へんな働き方
yusukebe
5
2.8k
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
280
Rethinking API Platform Filters
vinceamstoutz
0
150
Windows on Ryzen and I
seosoft
0
360
ロボットのための工場に灯りは要らない
watany
11
3.1k
飯MCP
yusukebe
0
240
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
3
1.8k
条件判定に名前、つけてますか? #phperkaigi #c
77web
2
760
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
2
850
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
180
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
150
Marketing to machines
jonoalderson
1
5k
BBQ
matthewcrist
89
10k
Site-Speed That Sticks
csswizardry
13
1.1k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
770
Design in an AI World
tapps
0
180
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
200
Crafting Experiences
bethany
1
93
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
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?