Garbage collection

Garbage collection is how memory is recovered from your program. It is a form of automatic memory management: languages like python, r and Java also have automatic memory management. Without it you need to make explicit calls in your code to tell the operating system you are done using memory. Languages like c and c++ do not have automatic memory management. You can read more here.

If your program is spending a lot of time on garbage collection that often means you are allocating a lot of memory; e.g. creating lots of large arrays. Sometimes you can improve it by using mutable commands (e.g. sort! instead of sort).

Note that @time may not be accurate and you should probably use @btime from BenchmarkTools

It’s hard to give you any more specific advice without seeing the specific code: that’s the advantage of a MWE.

8 Likes