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
0
74
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
930
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
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
250
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
600
Oxlintはいいぞ
yug1224
5
1.3k
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
380
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
990
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
640
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
150
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
140
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Faster Mobile Websites
deanohume
310
31k
How to build a perfect <img>
jonoalderson
1
4.9k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
49k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
110k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Automating Front-end Workflow
addyosmani
1371
200k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.2k
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?