2. Your team wrote a python program to do
station recommendations
You run it
After 10 min you machine grinds to a halt and
a cryptic “out of memory” appears
You go and make some coffee/tea
So...
3. Memory management in python
Once upon a time there were only references
But then the reference cycles appeared and
multiplied
And then there was gc, and Guido saw that it
was good
5. More on GC
Two triggers: manual and on allocation
threshold
Internally tracks all containers and looks for
cycles
Common wisdom is to run it once after your
initialisation phase, then every so often
Avoid __del__! (same as in Java)
6. memory_profiler module
Adds a @profile annotate
Uses psutil to track memory consumption
Covers C-side allocations
Supports plotting memory usage over time
9. Good old printf debugging
What I ended up using was… printf!
Wire up psutil into the python-core logger
Get a basic memory usage throughout the
application lifetime