This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]