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
76
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
950
Python Fest lightning talk
oinopion
0
93
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
tRPCの概要と少しだけパフォーマンス
misoton665
2
250
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
Back to the roots of date
jinroq
0
550
t *testing.T は どこからやってくるの?
otakakot
1
830
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
480
第3木曜LT会 #28
tinykitten
PRO
0
120
🦞OpenClaw works with AWS
licux
1
310
2026年のソフトウェア開発を考える(2026/05版) / Software Engineering Scrum Fest Niigata 2026 Edition
twada
PRO
11
3.4k
의존성 주입과 모듈화
fornewid
0
150
Kingdom of the Machine
yui_knk
2
1.2k
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
280
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
5.9k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
230
A Soul's Torment
seathinner
6
2.7k
Designing Powerful Visuals for Engaging Learning
tmiket
1
350
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
We Are The Robots
honzajavorek
0
220
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Curse of the Amulet
leimatthew05
1
12k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
540
Utilizing Notion as your number one productivity tool
mfonobong
4
300
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?