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
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
230
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
850
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
160
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
2.2k
AI主導でFastAPIのWebサービスを作るときに 人間が構造化すべき境界線
okajun35
0
460
エージェント開発初心者の僕がエージェントを作った話と今後やりたいこと
thasu0123
0
220
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
5
860
Claude Code、ちょっとした工夫で開発体験が変わる
tigertora7571
0
190
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
140
CSC307 Lecture 14
javiergs
PRO
0
450
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
200
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
110
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Building an army of robots
kneath
306
46k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
360
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Paper Plane (Part 1)
katiecoart
PRO
0
5k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.1k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
The Language of Interfaces
destraynor
162
26k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
470
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?