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
87
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
970
Python Fest lightning talk
oinopion
0
95
Contributing to Django
oinopion
2
600
Django and Time Zones: New in the Trunk
oinopion
4
220
Other Decks in Programming
See All in Programming
React本体のコードリーディング
high_g_engineer
1
150
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
140
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
140
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
140
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
170
リアルな遅延を測る仕様
kota_yata
1
120
30年振りにコンパイラの定数整数除算を改善した
herumi
9
3.9k
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
120
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
360
Flow は今どうなっているか
mizdra
PRO
0
670
メールのエイリアス機能を履き違えない
isshinfunada
0
250
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
800
Faster Mobile Websites
deanohume
310
32k
Google's AI Overviews - The New Search
badams
0
1.1k
Deep Space Network (abreviated)
tonyrice
0
270
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
500
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
480
A better future with KSS
kneath
240
18k
The SEO Collaboration Effect
kristinabergwall1
1
530
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Optimizing for Happiness
mojombo
378
71k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
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?