[Bug libstdc++/53169] Memory leak in std::vector<std::vector*>

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Apr 30 14:59:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53169

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-30 14:59:05 UTC ---
By changing your main to:

int main() {
    test();
    sleep(10);
        char* p = (char*)malloc(1024 * 127);
        for (int i=0; i < 100; ++i)
            p[1024 * i] = 'a' + (i%26);
        sleep(10);
        free(p);
        sleep(10);
    return 0;
}

I see that freeing the small malloc'd memory region (which is below glibc's
MMAP_THRESHOLD value) does actually trigger the earlier new'd memory to be
returned to the system too.

So it's possible to get the memory libstdc+ allocates to be returned to the
system, but it's under the control of glibc, nothing to do with std::vector or
libstdc++

If your memory usage patterns don't result in memory being returned then there
are several posibilities, including not freeing memory when you think you are,
or fragmenting the heap so that later allocations cannot re-use memory returned
to freelists and must allocate new memory using mmap.

Not a GCC bug though.



More information about the Gcc-bugs mailing list