Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
Memory usage of program increasing over time, but memory leak tools report no issues

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:

chart of memory usage

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;
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You are most likely suffering from memory fragmentation.

What happens is that as you release chunks of memory, you get little holes which might not be able to be used next time you request memory. As you continue allocating and releasing in a pattern that creates small unusable holes, the only solution is to get more hunks of memory from the system.

If you have well-defined rules for how your program uses memory for specific things, you might want to consider a memory pool to help allocate and release memory according to the specific requirements of your program, rather than the general-purpose requirements of the standard library.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!