Is this a sign of heap fragmentation?
To test if my object had a memory leak, I instanced it 10000 times and deleted it 10000 times. After, my program was using about 500kb more. I do not th开发者_运维百科ink my object is leaking though.
Thanks
On Linux at least, the C library does not release memory back to the OS just because you call delete
. It puts the memory on a "free list" inside your process. So if you are using a command like top
or cat /proc/XXX/status
to measure the virtual memory use, you will see the size consumed by everything in your process including that free list.
The C library only releases memory back to the system when you free
or delete
a "large" object. The definition of "large" is something like 128K bytes.
I suspect Windows, Mac, etc. work similarly but I do not know for sure.
So the short answer to your question is "No, not necessarily".
Depending on what your class actually contains and does, what you describe can happen, even if your class doesn't leak.
Some standard library implementations allocate class like std::string
from memory pools.
You should use an actual leak checker like valgrind instead of your test runs.
精彩评论