Python Memory Management and Tips Transcripts
Chapter: Investigating memory usage
Lecture: A memory profiler

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw that the CPU profiler, basically see Cprofile, built in to PyCharm, is not gonna
0:05 do it for memory analysis. So how about we get a memory profiler like "memory_
0:12 profiler" for Python? Yeah,
0:14 that's what we're gonna use. So memory profiler is
0:17 a way that we can capture much more fine grain detail about what our program
0:22 is doing in terms of memory consumption, and those pictures I showed you before where the
0:27 graphs of memory usage over time, those came from this tool and we'll see how
0:31 to make them here. So to get it as super easy, we're just going to pip
0:35 install memory_profiler. Technically, we're gonna add memory_profiler over to our requirements file,
0:42 and then we have several ways to use it.
0:44 You can decorate a single function and then run it like this.
0:50 Run it through the module "memory_
0:52 profiler", and you'll get all sorts of cool output like this about how much
0:56 each line of code is using.
0:59 That's pretty cool. We're gonna do that.
1:01 You can also just say "go and run it".
1:04 Say there's a "mprof" command we'll have once we install Memory Profiler.
1:08 And when we do that, then we can run, it says executable,
1:11 this is just your Python script, and then it will profile it,
1:14 and then we can plot that.
1:16 So we'll get graphs like I showed you before,
1:18 like down here, Okay?
1:20 So we're gonna go through both of these styles of working with Memory Profiler.
1:25 It's Open source, It was recently updated a couple months ago.
1:30 It seems to work pretty well.