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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Tomek Paczkowski
November 28, 2013
Programming
85
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
960
Python Fest lightning talk
oinopion
0
93
Contributing to Django
oinopion
2
590
Django and Time Zones: New in the Trunk
oinopion
4
220
Other Decks in Programming
See All in Programming
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
190
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.5k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
970
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
200
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
190
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
220
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
260
A2UI という光を覗いてみる
satohjohn
1
160
JavaDoc 再入門
nagise
1
420
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
170
YesSQL, Process and Tooling at Scale
rocio
174
15k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
170
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
WCS-LA-2024
lcolladotor
0
660
Docker and Python
trallard
47
3.9k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Producing Creativity
orderedlist
PRO
348
40k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
Design in an AI World
tapps
1
250
The Invisible Side of Design
smashingmag
301
52k
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?