The memory should be freed when a program exits (regardless if the program freed it or not). For example.
[kbrandt@ny-kbrandt01: ~] cat eat_mem.c
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main()
{
#1 GByte
const int m = 1024*1024*1024;
#Allocate a gig
void *p = (int*)malloc(m);
#Write a Gigs worth of zeros to that gig
memset(p,0,m);
sleep(10);
#In theory I should free(p) here (heh... heh... I said "free p", get it?)
return 0;
}
[kbrandt@ny-kbrandt01: ~] gcc eat_mem.c; ./a.out &; sleep 1; free -m;sleep 10; free -m
[1] 10666
total used free shared buffers cached
Mem: 7872 1848 6023 0 143 431
-/+ buffers/cache: 1273 6599
Swap: 30467 0 30467
[1] + done ./a.out
total used free shared buffers cached
Mem: 7872 823 7049 0 143 431
-/+ buffers/cache: 247 7624
Swap: 30467 0 30467
So assuming your script run the by the cron job exits, that would not be the issue. So you need to see which program is growing in memory. You can just watch this using top
(You can sort by resident memory size by pressing F
(capital) and then q
for RES in top) and see what program grows.
My guess is that it is going to be MySQL, because whatever your script does, it does stuff in SQL and SQL ends up using more memory. This probably actually isn't a problem if I had to guess, MySQL will take the memory it can get and use it wisely most of the time.