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
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
AHC061解説
shun_pi
0
280
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
380
20260228_JAWS_Beginner_Kansai
takuyay0ne
5
410
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
450
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
150
日本だけで解禁されているアプリ起動の方法
ryunakayama
0
360
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
160
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
440
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.4k
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
570
CSC307 Lecture 10
javiergs
PRO
1
690
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
210
Featured
See All Featured
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
430
Claude Code のすすめ
schroneko
67
220k
WENDY [Excerpt]
tessaabrams
9
36k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
210
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
340
The Invisible Side of Design
smashingmag
302
51k
Paper Plane (Part 1)
katiecoart
PRO
0
5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
63
53k
The Pragmatic Product Professional
lauravandoore
37
7.2k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
67
37k
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?