Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Python Memory Management
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Tomek Paczkowski
November 28, 2013
Programming
89
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
980
Python Fest lightning talk
oinopion
0
97
Contributing to Django
oinopion
2
610
Django and Time Zones: New in the Trunk
oinopion
4
220
Other Decks in Programming
See All in Programming
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
820
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
300
[2026-10-14](C)Re:ゼロから始める異世界生活〜始まりの終わりと終わりの始まり〜
tosite
0
140
残高管理から台帳サービスへの進化
artoy
1
210
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.2k
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
510
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
190
JIS keyboard support in Omarchy
lef237
0
150
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
3
1k
ジョジョの世界をXRで再現する
mofurune
0
180
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.7k
Kotlinの15年とServer-Side Kotlin
n_takehata
1
160
Featured
See All Featured
We Are The Robots
honzajavorek
0
400
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
WCS-LA-2024
lcolladotor
0
900
GraphQLとの向き合い方2022年版
quramy
50
15k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
580
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
430
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
500
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
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?