For a 64-bit OS, is a memory leak still relevant?

If you have a 64-bit OS, you have an address space of almost unlimited size. So my question is: is memory freedom really important on such systems? Even if you have limited RAM, say 4 GB, in the demand paging scheme (the memory was brought in only by touching), the small overhead that you get compared to freeing up the memory is a few extra page swaps that, like me I believe not to touch for a long time, will be automatically replaced. Am I missing something? Or is my argument true?

In practice, if this is not a big success, then I think this is good for C / C ++ programmers, as memory leaks will no longer be an important issue to solve the problem!

+4
source share
8 answers

overhead ... these are a few extra page swaps ... since the memory ... will be automatically replaced

Automatically swap places where? Ether? Page files are finite, as is the storage on which they exist.

Do you find it a good idea to never free memory in a long-term service application?

+11
source

I think the key word here is "practically" - the definition of which comes down to "not really." You have a memory space that is not really limited. All that really changed with the increase in memory availability is the amount of application that you can afford to be heartless about managing memory.

In other words, if you write "Hello World", then of course you can leave your memory garbage in its place. These days, you could probably leave with a small application that did not manage your own memory. But if you write a device driver or a service daemon that should work as long as the operating system is running ... well, I donโ€™t want to reset the production machine once a week to manually clear any other leak memory.

+3
source

This is not just the best practice for cleaning up memory allocated earlier.

If all programs stop releasing a block of memory due to performance reasons, you will see what happens.

Yes, it is very important.

+2
source

It depends on the application. In some applications, a large batch is allocated (for example, several hundred megabytes per second). If you think you will never free this, but use swap space, you will close the exchange of several gigabytes in a few hours.

See the huge literature on garbage collection, for example. a garbage collection reference to get you started.

Andrew Appel's old article, garbage collection can be faster than stack distribution , should give you interesting ideas.

However, you might consider a garbage collector that leaks a little, then the leak rate will be only a few megabytes per minute (after the GC), and the situation will be different.

And when you consider only short-term applications, memory leak is really less important. But once you have long server processes, you have to take care of memory and never release (or reuse), this is a bad idea.

+2
source

Yes, this might make sense for short-life tools like command line utilities like ls .

For example, Busybox even has a configuration parameter that controls whether free memory will be a common occurrence, or let the OS automatically clear it at the output.

FEATURE_CLEAN_UP

As a size optimization, busybox usually exits without explicitly freeing dynamically allocated memory or closing files. This saves space since the OS will be cleaned up for us, but it can confuse debuggers like valgrind, which report tons of memory and resource leaks.

Do not enable this unless you have a really good reason for manually cleaning things.

+2
source

The address space may seem almost endless, but the physical storage on any current computer is definitely not. OS (any OS, not just Linux) does not know that an application is executed using a memory page unless it is explicitly freed. Slow pages still require disk space and CPU / I / O time to process.

From my experience, even in the few cases when some enticing marketer managed to sell computer systems that met the requirements, available memory still became a problem after a while.

Also, if you want to know what will happen if the application stops freeing up memory, just take a look at the application, which is simply leaking / using memory, and not just refusing to free it. For example, Firefox, after several hours of tabbed activity, will soon rise to 3 GB on my 8 gigabyte system. I donโ€™t even want to imagine how high this figure is without any freeing up of memory.

Now imagine that ten applications do the same thing at the same time - I am alone, I do not have 30 GB of physical or virtual memory on my desktop system. And if my system already crashes with just one instance of Firefox, I'm afraid what will happen in your proposed scenario ...

+2
source

If you think that the worst that can happen if not free() > memory is a failure, you should consider what happens when:

  • You cannot assign a socket buffer, and you need to start removing packets.
  • You experience a drop in performance (always, since you always flow) from fainting.
  • You probably can no longer create debug / diagnostic logs and / or messages.
  • You have run out of file descriptors.

The bottom line has free allocated memory. It will save your health.

+1
source

If you have a 64-bit OS, you have an almost unlimited address space

This part that you seem to miss is the virtual part.

First of all, you are always "limited" by the actual RAM.

And I mean the restriction as follows:
In the 4 GB example, you mention that if the process does not free up memory and continues to request new memory, the OS will start using HD to exchange virtual pages.

You will have page crashes and access to HD, which will entail heavy operating costs for the process and for the entire system if this happens for all running processes (after you think that this is normal). As a result, in order for the user to have a โ€œconvenientโ€ system, he would have to buy more and more RAM.
What do you think the user will respond if you said your system is not responding, but you just need to buy more RAM, for example. 16 GB or 32 GB or .....

0
source

Source: https://habr.com/ru/post/1391088/


All Articles