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
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
920
Python Fest lightning talk
oinopion
0
91
Contributing to Django
oinopion
2
570
Django and Time Zones: New in the Trunk
oinopion
4
210
Other Decks in Programming
See All in Programming
AtCoder Conference 2025
shindannin
0
790
Patterns of Patterns
denyspoltorak
0
380
AIエージェントの設計で注意するべきポイント6選
har1101
6
2.6k
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
170
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
140
クラウドに依存しないS3を使った開発術
simesaba80
0
180
Cell-Based Architecture
larchanjo
0
150
複雑なUI設計への銀の弾丸 「オブジェクト指向UIデザイン」
teamlab
PRO
2
110
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
130
チームをチームにするEM
hitode909
0
410
脳の「省エネモード」をデバッグする ~System 1(直感)と System 2(論理)の切り替え~
panda728
PRO
0
130
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
230
Featured
See All Featured
A Soul's Torment
seathinner
1
2k
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.2k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
2
68
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.2k
The Curse of the Amulet
leimatthew05
0
5.8k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
410
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Applied NLP in the Age of Generative AI
inesmontani
PRO
3
2k
Skip the Path - Find Your Career Trail
mkilby
0
28
It's Worth the Effort
3n
187
29k
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?