Why memory can't be collected cleanly after a process terminats?

0

After long time running, computers always become slow. Rebooting generally make them faster. But how does this happen?

Initally I thought this might be related to memory usage. But recently I learned the concept of virtual memory. I think if I close all unnecessary processes, which cause kernel to destroy their page tables and thus release/free their usage of (at least virtual) memory, the system should be as clear as just startup.

But actually that doesn't work. Where am I wrong? Please suppose linux environment if necessary.

wlnirvana

Posted 2014-08-01T05:36:57.860

Reputation: 103

1

Personally I have never experienced that, at least in Linux (unless there have been stability issues, but I suppose you're not talking about such). However, Linux memory management doesn't work as you seem to expect, at least for RAM, as it will try to use all of it (for buffers/cache). It does some balancing between swapping out pages to disk to gain more buffer/cache room and keeping pages in RAM to improve responsiveness. This can be controlled by swappiness (v2.6->) which you can try out if you suspect being hit by virtual memory management.

– zagrimsan – 2014-08-01T05:55:11.620

2You should also provide more evidence on the status of your system to be able to hold the assumption you represent in the question title (that memory isn't cleanly collected after process termination). – zagrimsan – 2014-08-01T05:56:24.503

Answers

2

The premise of this question is incorrect.

Linux, Windows, and OSX all track and properly clean up allocated memory, open file handles, open sockets, and other system resources used by the process when it terminates.

Drivers and the kernel itself are still capable of leaking memory, but the only actual/noticable memory leak that I've encountered in the past 10 years is Creative's SoundBlaster drivers on windows, and even that is easily fixed by restarting the Windows Audio Service.

Darth Android

Posted 2014-08-01T05:36:57.860

Reputation: 35 133

Well, that’s not entirely correct either. Some shared resources, e.g. semaphores, cannot be released. – Daniel B – 2014-08-01T07:28:47.200

I would expect them to be freed after the last process using them closes. Is that not the case? – Darth Android – 2014-08-01T07:32:37.793

The problem is that semaphores aren’t “used”. Here’s some more on the topic.

– Daniel B – 2014-08-01T07:42:19.570

So as long as I close my running process, rebooting actually doesn't provide any more help? – wlnirvana – 2014-08-01T14:07:00.650

@wlnirvana 99% of the time, no, not in the way you think it does. – Darth Android – 2014-08-02T01:53:33.253

@DarthAndroid In Windows, a semaphore most certainly is freed when the last handle to it is closed. The handles opened by a process are closed automatically when the process exits. So, in Windows, they most certainly are freed. – Jamie Hanrahan – 2019-03-12T14:35:20.873