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
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
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
200
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
970
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
CSC307 Lecture 05
javiergs
PRO
0
500
Oxlint JS plugins
kazupon
1
810
AgentCoreとHuman in the Loop
har1101
5
230
AI & Enginnering
codelynx
0
110
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
Architectural Extensions
denyspoltorak
0
280
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
Featured
See All Featured
Test your architecture with Archunit
thirion
1
2.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Marketing to machines
jonoalderson
1
4.6k
Embracing the Ebb and Flow
colly
88
5k
Six Lessons from altMBA
skipperchong
29
4.1k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
110
Skip the Path - Find Your Career Trail
mkilby
0
53
Art, The Web, and Tiny UX
lynnandtonic
304
21k
How to train your dragon (web standard)
notwaldorf
97
6.5k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
55
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
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?