Re: memory leak with deque ?
mast2as@yahoo.com wrote:
Hi again
I was still debugging some code and check for memory leaks with
valgrind and found out that valgrind finds a leak when i use
deque<Something> aqueue ?! I am compiling under Linux
for example:
#include <deque>
using namespace std;
int main()
{
deque<int> test;
test.clear();
return 0;
}
is there something I can do or I am doing something wrong ?
Obviously, your code and the library code are fine. Your interpretation
(or configuration) of valgrind is the problem.
Thanks -
valgrind output
===========
==18232== 1280 bytes in 1 blocks are still reachable in loss record 1
of 1
==18232== at 0x1B90406F: operator new(unsigned)
(vg_replace_malloc.c:133)
==18232== by 0x1B986B9A: std::__default_alloc_template<true,
0>::_S_chunk_alloc(unsigned, int&) (stl_alloc.h:108)
That looks like a false memory leak report by valgrind. Note it mentions
that the memory is still "reachable". All that is happening is that the
library implementation is using a caching allocator, that holds onto
memory that is freed so that it can reuse it later.
You should be able to switch this caching behaviour off, just for the
purposes of memory leak detection. Have a look at your library
documentation under allocators to see how to disable it. e.g.
http://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html
Tom