Igazából azonosítanod kellene inkább, hogy melyik folyamat birtokolja a memóriát, amit nem kéne neki. Ha egy programot bezársz, akkor azokat az erőforrásait, amikről tud a kernel fel is szabadítja (ha a program nem tette meg magától).
Kísérlet:
norbi@martin:~/tmp$ cat memory.c
#include <stdlib.h>
#include <stdio.h>
#define BUFFLENGTH (1024*1024*500)
int main()
{
char *buff;
unsigned i;
buff = (char*)malloc(BUFFLENGTH);
for (i=0; i<BUFFLENGTH-1; ++i) buff[i]=i;
printf("Memory allocated and messed up!\n");
scanf("%s",buff);
return 0;
}
norbi@martin:~/tmp$ gcc -Wall -ansi -pedantic memory.c -o memory
norbi@martin:~/tmp$ free -m
total used free shared buffers cached
Mem: 3827 3447 379 0 23 1209
-/+ buffers/cache: 2215 1612
Swap: 5118 186 4932
norbi@martin:~/tmp$ ./memory
Memory allocated and messed up!
^Z
[1]+ Megállítva ./memory
norbi@martin:~/tmp$ free -m
total used free shared buffers cached
Mem: 3827 3750 77 0 13 1030
-/+ buffers/cache: 2706 1121
Swap: 5118 190 4928
norbi@martin:~/tmp$ fg
./memory
foo
norbi@martin:~/tmp$ free -m
total used free shared buffers cached
Mem: 3827 3251 576 0 13 1026
-/+ buffers/cache: 2211 1615
Swap: 5118 190 4928
norbi@martin:~/tmp$
A memory leak néven jelentkezett probléma a program futása közben érvényes igazából, ha már kiléptél belőle, akkor az általa foglalt memóriának fel kell szabadulni!