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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
930
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
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
今から始めるClaude Code超入門
448jp
8
8.5k
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
600
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.1k
CSC307 Lecture 06
javiergs
PRO
0
680
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
6.9k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
520
2026年 エンジニアリング自己学習法
yumechi
0
130
AI巻き込み型コードレビューのススメ
nealle
0
140
Featured
See All Featured
WENDY [Excerpt]
tessaabrams
9
36k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
930
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
220
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
77
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.9k
How to Ace a Technical Interview
jacobian
281
24k
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?