You aren’t really running out of memory on Linux
From Slashdot Poll | How often do you reboot your …
Re:Firefox memory leak (Score:5, Informative)
by pablomme (1270790) on Monday May 11, @11:26PM (#27917407)
Leaked memory is associated with the process, and is released by the kernel when you quit, and that is true of more or less all modern OSs.
If you think that you’re not getting the memory back, it probably means that you are not aware of the fact that the Linux kernel uses free memory as cache with a policy of filling the RAM to the brim whenever possible, and only drop cached stuff when programs need the space. Memory appears full in most reports if you don’t subtract the cache.
Re:Firefox memory leak (Score:4, Informative)
by TheRaven64 (641858) on Tuesday May 12, @08:46AM (#27920507) Homepage Journal
This is the same on most operating systems. On a classic UNIX system, you allocated memory with brk() to increase the data segment and sbrk() to increase the stack segment. Modern UNIX tends to use mmap() to allocate pages and the malloc() C library function allocates space within these pages. The mmap() call is also used to map other files into memory.
When you allocate some memory in a *NIX process, you are really mapping a region of an anonymous file. As a simple efficiency hack, this may not actually be associated with a real, on-disk, file until it actually needs to be swapped out.
The unified buffer cache idea means that the same policy is applied to deciding whether to swap out a page, irrespective of whether it’s in swap or in the filesystem (although an implementation my choose to prioritise evicting pages backed by devices with low access times).
When you think about low-level operations, it makes very little difference whether something was allocated with mmap() or malloc() (you than think of read() as roughly equivalent to mmap(), malloc(), and memcpy()). If the data that is needed is available, the operation will be fast. If not, it will be slow. Prioritising memory that the program malloc()’d when it launched and then never touched again over data read recently or frequently from the disk would make no sense.
Re:Firefox memory leak (Score:5, Informative)
by QuoteMstr (55051) <dan.colascione@gmail.com> on Tuesday May 12, @10:59AM (#27922247)
Don’t comment on things you don’t understand. The kernel keeps track of all resources allocated on behalf of each process — file descriptors, sockets, memory regions, you name it. When a process terminates, no matter how, the kernel frees its associated resources.
Every virtual-memory operating system works this way. Come on, this is really basic stuff.