I am working on a fairly large library that continuously allocates and frees memory as it executes. For the past few weeks I have been trying to keep the memory consumption stable, but it appears to be increasing over time. The behavior I can't quite explain is that the increase is not linear. There is a "baseline" memory level that the process hovers at for a while, and then it jumps to a new "baseline". As time passes, the jump entails more and more memory. So let's say memory usage jumped from 512kb to 1024kb after a few hours of operation. It might go from 1024 to 2048 overnight hours. Then it might jump to 4096kb next time. Here is a chart of what memory usage looks like:
I have it running on Linux and Valgrind gives it a clean bill of health, if this is relevant at all. I am using the Linux code here to display the virtual memory consumption of my process:
int getValue(){ //Note: this value is in KB!
FILE* file = fopen("/proc/self/status", "r");
int result = -1;
char line[128];
while (fgets(line, 128, file) != NULL){
if (strncmp(line, "VmSize:", 7) == 0){
result = parseLine(line);
break;
}
}
fclose(file);
return result;