Python Memory Management and Tips Transcripts
Chapter: Investigating memory usage
Lecture: Profiling introduction

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In carpentry, there's a saying "measure twice, cut once",
0:03 and something like that should probably apply to software.
0:07 When we think we need to make changes for improving our code,
0:10 we should probably measure it before we go make those changes.
0:15 My experience has been that we are very,
0:18 very bad at guessing exactly what is expensive and what is not in software.
0:23 Sometimes this has to do with memory,
0:25 sometimes it has to do a CPU speed.
0:27 Often there's a relationship between those things.
0:30 So in this section, we're going to talk about measuring memory usage and using tools to
0:36 exactly understand what's happening, and then we can make changes and see how they're improving.
0:41 And we did that in a coarse-grained way before with our report memory thing
0:45 that we did, it said "well,
0:46 looks like the process gained this much memory from this step to that step",
0:51 but all we were actually doing is asking how much memory is the process using now, or
0:55 how much resident memory are we using right now,
0:59 and that can change based on things that are not exactly to do with allocation.
1:04 We could have shared memory, other stuff could be happening in the operating system, the GC
1:09 could be holding on to memory for a while,
1:11 Who knows? So what we're gonna do is we're going to use some tools to
1:14 go and investigate and get more precise numbers about exactly what and where and how we're
1:20 using memory.