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
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
570
Django and Time Zones: New in the Trunk
oinopion
4
210
Other Decks in Programming
See All in Programming
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
190
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4k
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
Architectural Extensions
denyspoltorak
0
240
SourceGeneratorのススメ
htkym
0
130
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
160
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
180
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
130
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
150
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
900
Oxlintはいいぞ
yug1224
5
1.1k
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
180
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
2
230
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
130
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
340
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
620
Joys of Absence: A Defence of Solitary Play
codingconduct
1
280
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
110
Evolving SEO for Evolving Search Engines
ryanjones
0
100
Are puppies a ranking factor?
jonoalderson
1
2.6k
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
150
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?