Your memory profile is actually a need for the process address space (the sum of mmap -ed pages, for example, given by /proc/self/statm or /proc/self/maps from the point of view of the process itself).
But when the C or C ++ memory deallocation function (previously allocated with malloc or new , which use mmap to get memory from the Linux kernel) with free or delete , it is not (using munmap because it would be too slow or impractical [fragmentation problems] - but just saved as reusable for the future malloc or new .
Thus, the release occurs at the request free , but the memory is not returned to the system, but is saved for later reuse.
If you really want to get the memory back, write your own allocator (above mmap and munmap ), but this is usually not worth the effort.
Perhaps using a Boehm GC might help (very useful so as not to worry about free -ing or delete -ing) if you explicitly call GC_gcollect() (but I'm not sure about that), but you really shouldn't worry about that.
And your question is not technically related to gcc (this would be the same with another C ++ compiler). It is associated with malloc and new (i.e. with standard C and C ++ libraries) under Linux.
source share