Identifying Memory Leaks in Complex Memory-Intensive Applications Using Massif

Hi everyone,

I’ve been using Massif for profiling memory in a memory-intensive application (you can check the documentation here:(site.developer.gnome.org/documentation/tools/massif.html). However, I’ve hit a challenge where Massif shows a continuous increase in memory usage, but it’s not clear which part of the application is responsible for the leak.

For context, the application involves multiple data processing steps and uses a large number of dynamic memory allocations throughout. I’ve already used the --depth and --alloc-fn parameters, but the leak remains elusive, even after analyzing the graphical output.
Sample Code:

#include <stdlib.h>
#include <glib.h>

void process_data() {
    gchar *data = g_strdup("large data chunk");
    // Do some processing with data
    // But forgot to free 'data'
}

int main() {
    for (int i = 0; i < 100000; i++) {
        process_data();
    }
    return 0;
}

In the example above, the program allocates memory for each data string but never frees it, leading to a gradual increase in memory usage. Massif identifies that memory is being allocated in g_strdup, but I can’t pinpoint the exact location in the code that causes the memory growth because the allocation is done in a loop.

Has anyone encountered a similar issue with complex memory leaks? Or can Massif be configured to track such dynamic memory allocations more precisely, even in loops and recursive functions? I’d appreciate any tips on improving memory tracking to catch these subtle leaks.

Thanks!

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.