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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Tomek Paczkowski
November 28, 2013
Programming
75
0
Share
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
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
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
180
おれのAgentic Coding 2026/03
tsukasagr
1
140
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
1.8k
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
220
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
230
へんな働き方
yusukebe
6
2.9k
CDK Deployのための ”反響定位”
watany
0
400
AIエージェントで業務改善してみた
taku271
0
500
Don't Prompt Harder, Structure Better
kitasuke
0
450
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
440
Codex CLI でつくる、Issue から merge までの開発フロー
amata1219
0
330
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
150
Featured
See All Featured
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
340
Exploring anti-patterns in Rails
aemeredith
3
310
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
170
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
710
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
160
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
150
The browser strikes back
jonoalderson
0
900
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Site-Speed That Sticks
csswizardry
13
1.1k
So, you think you're a good person
axbom
PRO
2
2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
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?