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
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
350k
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
590
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
410
Oxcを導入して開発体験が向上した話
yug1224
4
340
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
240
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
190
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.4k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
The NotImplementedError Problem in Ruby
koic
1
950
Creating Composable Callables in Contemporary C++
rollbear
0
170
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
280
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
560
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
210
How to train your dragon (web standard)
notwaldorf
97
6.7k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
450
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
540
Producing Creativity
orderedlist
PRO
348
40k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
250
KATA
mclloyd
PRO
35
15k
Ethics towards AI in product and experience design
skipperchong
2
320
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
240
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
330
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?