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
70
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
860
Python Fest lightning talk
oinopion
0
90
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
高単価案件で働くための心構え
nullnull
0
160
Evolving NEWT’s TypeScript Backend for the AI-Driven Era
xpromx
0
190
AIを駆使して新しい技術を効率的に理解する方法
nogu66
1
660
AIエージェントでのJava開発がはかどるMCPをAIを使って開発してみた / java mcp for jjug
kishida
4
770
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
1
270
「正規表現をつくる」をつくる / make "make regex"
makenowjust
1
790
競馬で学ぶ機械学習の基本と実践 / Machine Learning with Horse Racing
shoheimitani
14
13k
2025 컴포즈 마법사
jisungbin
0
150
手軽に積ん読を増やすには?/読みたい本と付き合うには?
o0h
PRO
1
110
Feature Flags Suck! - KubeCon Atlanta 2025
phodgson
0
160
AIの弱点、やっぱりプログラミングは人間が(も)勉強しよう / YAPC AI and Programming
kishida
13
5.3k
DartASTとその活用
sotaatos
2
150
Featured
See All Featured
Done Done
chrislema
186
16k
Music & Morning Musume
bryan
46
7k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
How to Ace a Technical Interview
jacobian
280
24k
Designing for Performance
lara
610
69k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Docker and Python
trallard
46
3.7k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.1k
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?