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
82
0
Share
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
950
Python Fest lightning talk
oinopion
0
93
Contributing to Django
oinopion
2
590
Django and Time Zones: New in the Trunk
oinopion
4
220
Other Decks in Programming
See All in Programming
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
120
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
980
ローカルLLMでどこまでコードが書けるか / How much code can be written on a local LLM
kishida
2
410
TSKaigi 2026 TypeScriptバックエンドのオブザーバビリティ戦略 — Datadog × NestJSの実践
taiseiyamamotoan
1
190
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
0
330
RailsTokyo 2026#4: AI様があれば、 Hotwireの弱点は消えるか?
naofumi
5
930
新規プロダクトを高速で生み出すハーネスエンジニアリング
seanchas116
3
270
Agentic UI beyond Chats Architecture Patterns & Open Standards @ngMunich 05/2026
manfredsteyer
PRO
0
140
OSもどきOS
arkw
0
130
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
160
20260514_its_the_context_window_stupid.pdf
heita
0
1.1k
AIエージェントの隔離技術の徹底比較
kawayu
0
430
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
エンジニアに許された特別な時間の終わり
watany
107
240k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
820
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
Deep Space Network (abreviated)
tonyrice
0
150
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Paper Plane (Part 1)
katiecoart
PRO
0
7.8k
Context Engineering - Making Every Token Count
addyosmani
9
900
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Navigating Weather and Climate Data
rabernat
0
200
Docker and Python
trallard
47
3.8k
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?