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
85
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
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
160
その節約、円になってますか?
isamumumu
0
630
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
570
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
0
600
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
290
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
290
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
790
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
370
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.3k
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
200
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
150
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
750
Featured
See All Featured
Optimizing for Happiness
mojombo
378
71k
Practical Orchestrator
shlominoach
191
11k
Product Roadmaps are Hard
iamctodd
55
12k
BBQ
matthewcrist
89
10k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
940
Automating Front-end Workflow
addyosmani
1370
210k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
260
Why Our Code Smells
bkeepers
PRO
340
58k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
430
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?