AutoPurger is a command line application I wrote. It is pretty basic and runs in Terminal. Suggested use is to copy it to the /Applications directory and add it as a Login Item for each user. The purpose of the application is to free inactive memory which would otherwise lead to system instability as free memory gets low. The program will free inactive memory once per hour or if it gets larger than 0.25GB (of course, you can tweak these to your liking). The only exception you might find to how this works is when you are working with RAM Disks, the ability to return inactive memory to free memory is not as predictable. In any event, you can put this into Xcode and build the command line application. It should be helpful to those who are always running low on memory or using Flash too much.
AutoPurger
------------
AutoPurger
------------
Code:
/*File: main.c*/
/*Project: AutoPurger (Command Line Application)*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <xlocale.h>
int main (int argc, const char * argv[]) {
static char apBuf[512], *apPtrStart = (char *) 0, *apPtrEnd = (char *) 0;
time_t cur = 0, start = 0, next = 0;
FILE *in = (FILE *) 0;
unsigned int i = 0;
int inactive = 0;
for (start = time((time_t *) 0), cur = start, next = cur + 3600; ; next = (cur < next) ? next : cur + 3600) {
cur = time((time_t *) 0);
if (cur >= next) {
system("/usr/bin/purge");
sleep(30u);
continue;
}
system("/usr/bin/top -stats mregion -l 1 >./AutoPurger.dat");
in = fopen("./AutoPurger.dat", "r");
if (!in) {
sleep(30u);
continue;
}
fread((void *) apBuf, 1, 500, in);
fclose(in);
in = (FILE *) 0;
apPtrStart = strstr(apBuf, "active, ") + 8;
apPtrEnd = strchr(apPtrStart, 'M');
*apPtrEnd = '\0';
inactive = atoi(apPtrStart);
for (i = 0; i < 512; i++) {
apBuf[i] = '\0';
}
if (inactive > 256) {
system("/usr/bin/purge");
sleep(30u);
continue;
}
sleep(30u);
}
return 0;
}