Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Small Memory Leaks Matter Anymore?

Tags:

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.

like image 389
lkessler Avatar asked Nov 12 '09 01:11

lkessler


People also ask

Are memory leaks still an issue?

Memory leaks may not be serious or even detectable by normal means. In modern operating systems, normal memory used by an application is released when the application terminates. This means that a memory leak in a program that only runs for a short time may not be noticed and is rarely serious.

Why should memory leaks be avoided?

Memory leak occurs when programmers create a memory in heap and forget to delete it. The consequences of memory leak is that it reduces the performance of the computer by reducing the amount of available memory.

Are memory leaks fixable?

In most cases, you can fix the Windows 10 memory leak issues yourself. You can close resource-intensive apps, disable certain startup apps, and perform similar tasks to fix a memory leak.

Does memory leak affect CPU usage?

Note: Applications with memory leaks can cause the CPU to work excessively. As a system's available RAM decreases, the system relies increasingly on the pagefile. The more heavily the pagefile is used, the more time is spent swapping pages between physical and virtual memory.


1 Answers

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.

like image 159
Reed Copsey Avatar answered Oct 05 '22 00:10

Reed Copsey