Perhaps you rarely face it, but once you do, you surely know what's wrong: lack of free memory, or Out of Memory (OOM). The results are typical: you can no longer allocate more memory and the kernel kills a task (usually the current running one). Heavy swapping usually accompanies this situation, so both screen and disk activity reflect this.
At the bottom of this problem lie other questions: how much memory do you want to allocate? How much does the operating system (OS) allocate for you? The basic reason of OOM is simple: you've asked for more than the available virtual memory space. I say "virtual" because RAM isn't the only place counted as free memory; any swap areas apply.
Exploring OOM
To begin exploring OOM, first type and run this code snippet that allocates huge blocks of memory:
#include <stdio.h>LUPA开源社区eL.a9uS \1^;@
#include <stdlib.h>
#define MEGABYTE 1024*1024
int main(int argc, char *argv[])LUPA开源社区.D%F%n
E2o
{
? Y3@O[
HL0 void *myblock = NULL;LUPA开源社区T5Q R;c`Bb
int count = 0;
while (1)LUPA开源社区F
t|3[D
{
L6J+l
V9Y#c nw@(R5J0 myblock = (void *) malloc(MEGABYTE);LUPA开源社区ox5Tv-DC
if (!myblock) break;LUPA开源社区R'hJ
?-b{,v
printf("Currently allocating %d MB\n", ++count);