- In general, there is some critical procedure that may be being performed at the moment. The problem is that during shutdown more errors can be generated in the event that to close something, you need to allocate more memory. Errors can vary between segfaults or silent crashes of the application, and are especially complicated to be dealt with in case they are released by a library that you do not own the source code.
Perhaps, your application caches something (from a file, for example), and then this cache can be released, allowing the application to even continue running. But such cases are rare and vary from application to application.
If it is not possible to free memory and system resources (file descriptors, etc), probably this may be the only solution, because it may be that at the time of logging, the operating system tries to allocate memory and then it also falls into a situation of bad_alloc
, and in this case its application shall be terminated by.
As discussed in 1., if your application creates caches or preallocates resources, it may be possible to release these resources and continue running the application normally.
This example I gave about the cache is used transparently by the Operating System.
When for example a file is opened and read, it is kept in memory for an indefinite time. Your changes, of course, are propagated to the secondary storage structure after a period of time (see parameter commit
of EXT4
for more information).
The file data is then kept in memory until it is full (see note below). Then, the operating system displaces memory previously occupied by the file cache until it is sufficient to allocate it to the application by requesting it. If you want to observe this behavior, the program top
, beyond the archive /proc/meminfo
are the simplest methods of seeing this condition (htop
does not display the numbers, not being very effective). The Task Manager
Windows also displays this data, although I find them a little less intuitive and Windows is a little more aggressive in the subject I deal with in observing down below.
Observing: Freeing up memory only when a program needs it is a costly operation that can degrade application performance. Thus, the Operating System actually always keeps a free memory area, allowing the memory to be more quickly delivered to the application that needs it. Upon delivery, the OS may or may not remove data from the cache, while always keeping a free amount of memory ready for allocation. It is worth noting that disk paging is the last case to be used by the OS (although Windows again loves to escape a little from this rule).
Just to illustrate, my machine (Gentoo) has 16GB of RAM and 8GB of swap. I am using 2.8GB in applications, 5GB of buffers, 6.8GB in caches (and 0GB of swap). That is, only 1.4GB is effectively free from my RAM.