R – Do Small Memory Leaks Matter Anymore

memory-leaks

With RAM typically in the Gigabytes on all PC's now, should I be spending time hunting down all the small (non-growing) memory leaks that may be in my program? I'm talking about those holes that may be less than 64 bytes, or even a bunch that are just 4 bytes.

Some of these are very difficult to identify because they are not in my own code, but may be in third party code or in the development tool's code, and I may not even have direct access to the source. In those cases, it would involve lengthy communication with the vendors of these products.

I have seen the number one memory leak question here at SO: Are memory leaks ever ok? and the number one answer to that, as of now voted up 85 times, is: No.

But here I'm talking about small leaks that may take an inordinate amount of debugging, research and communication to track down.

And I'm only talking about a simple desktop app. I understand that apps running on servers must be as tight as possible.

So the question I am really asking is, if I know I have a program that leaks, say 40 bytes every time it is run, does that matter?

A Single Drip
(source: beholdgenealogy.com)


Also see my followup question: What Operating Systems Will Free The Memory Leaks?


Postscript: I just purchased EurekaLog for my program development.

I found an excellent article by Alexander, the author of EurekaLog (who should know these things), about catching memory leaks. In that article, Alexander states the answer to my question very well and succinctly:

While any error in your application is always bad, there are types of errors, which can be not visible in certain environments. For example, memory or resources leaks errors are relatively harmless on client machines and can be deadly on servers.

Best Answer

This is completely a personal decision.

However, if:

So the question I am really asking is, if I know I have a program that leaks, say 40 bytes every time it is run, does that matter?

In this case, I'd say no. The memory will be reclaimed when the program terminates, so if it's only leaking 40 bytes one time during the operation of an executable, that's practically meaningless.

If, however, it's leaking 40 bytes repeatedly, each time you do some operation, that might be more meaningful. The longer running the application, the more significant that becomes.

I would say, though, that fixing memory leaks often is worthwhile, even if the leak is a "meaningless" leak. Memory leaks are typically indicators of some underlying problem, so understanding and correcting the leak will often make your program more reliable over time.