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
0
75
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
PHP 7.4でもOpenTelemetryゼロコード計装がしたい! / PHPerKaigi 2026
arthur1
1
390
Vuetify 3 → 4 何が変わった?差分と移行ポイント10分まとめ
koukimiura
0
180
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
1.1k
最初からAWS CDKで技術検証してもいいんじゃない?
akihisaikeda
4
170
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
1.3k
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
2
350
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
150
[SF Ruby Feb'26] The Silicon Heel
palkan
0
120
AI 開発合宿を通して得た学び
niftycorp
PRO
0
170
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
500
PHPのバージョンアップ時にも役立ったAST(2026年版)
matsuo_atsushi
0
240
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
140
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
0
280
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
360
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
120
Exploring anti-patterns in Rails
aemeredith
2
290
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
220
Un-Boring Meetings
codingconduct
0
240
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
110
Utilizing Notion as your number one productivity tool
mfonobong
4
270
How to make the Groovebox
asonas
2
2k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
580
Why Our Code Smells
bkeepers
PRO
340
58k
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?