Python Memory Management and Tips Transcripts
Chapter: Course conclusion and review
Lecture: Profiling

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw that we can investigate the memory used by our program in different ways: as
0:04 a picture over time, line by line, by peak memory usage,
0:08 all those things. And We looked at
0:10 two profilers: memory_Profiler and Fil. Fil's the one that measures the peak stuff best.
0:16 And this one here, memory_profiler,
0:19 let's us ask questions about line by line. So we add this decorator out of the
0:24 library, and then when we run it,
0:25 we just say "python -m memory_profiler",
0:28 give it the script, or the application to run, and the arguments,
0:32 it's a little bit slower. Well,
0:33 it's a lot slower, but,
0:34 you know, let it run and then out comes this really nice report of exactly how
0:39 much memory was used by each line,
0:41 what was gained, what was lost and so on.
0:43 So if you're worried about memory, take the time to stop and look.
0:47 Ask these tools "what's going on?" because there might be some part
0:51 where you think "I need to optimize here",
0:52 but it's actually some other line,
0:54 like something really simple, like,
0:56 "Oh, we're doing slicing" and it seems really minor,
0:59 but that actually makes a copy a bunch of times and turns out to be real
1:02 expensive or something along those lines.
1:04 Have a look with the tools that we showed you and investigate what your app is
1:08 doing and then apply some of the techniques that we've talked about to make it better.