At work, I accidently created some memory leaks in one of my previous tasks; but it is only discovered today
valgrind run before checking in my codes!) because of a program that used to finish in 30 hours now finished
in 2 to 3 days.
So what does memory leak has to do with program performance then?
In a computer system, data are stored both in memory and a secondary storage (such as hard drive) during a program run. For sake of maximum CPU usage, active data is usually kept in main memory ‘pages’ as much as possible, and non-active, or currently-not-in-use data is pushed out to secondary storage to make room, if necessary.
If the active data of a program cannot be held effectively within physical memory, which could be the case when lots of memory leaks take up significant amount of space in memory, then constant data swapping, i.e. thrashing, may occur. This in turn slows down the system performance significantly.
To read more about memory leaks? Check this post.
The next question would be: how to detect memory leaks before running the program? And how to avoid it?