473,226 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

memory leak with deque ?


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<Somethingaqueue ?! I am compiling under Linux

for example:
#include <deque>
using namespace std;

int main()
{
deque<inttest;
test.clear();
return 0;
}

is there something I can do or I am doing something wrong ?

Thanks -

valgrind output
===========
==18232==
==18232== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from
1)
==18232== malloc/free: in use at exit: 1280 bytes in 1 blocks.
==18232== malloc/free: 3 allocs, 2 frees, 1796 bytes allocated.
==18232== For counts of detected errors, rerun with: -v
==18232== searching for pointers to 1 not-freed blocks.
==18232== checked 2370932 bytes.
==18232==
==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)
==18232== by 0x1B986AAC: std::__default_alloc_template<true,
0>::_S_refill(unsigned) (stl_alloc.h:550)
==18232== by 0x1B9867A7: std::__default_alloc_template<true,
0>::allocate(unsigned) (stl_alloc.h:357)
==18232==
==18232== LEAK SUMMARY:
==18232== definitely lost: 0 bytes in 0 blocks.
==18232== possibly lost: 0 bytes in 0 blocks.
==18232== still reachable: 1280 bytes in 1 blocks.
==18232== suppressed: 0 bytes in 0 blocks.

Jul 6 '06 #1
4 4759
ma*****@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<Somethingaqueue ?! I am compiling under Linux

for example:
#include <deque>
using namespace std;
Why?
int main()
{
deque<inttest;
test.clear();
return 0;
}

is there something I can do or I am doing something wrong ?
What happens if you put the test code in its own scope or function?

--
Ian Collins.
Jul 6 '06 #2
using namespace std;
Why?
Hi Ian

I am assuming you ask why i am using "using namespace std" ?. No reason
really just because i am using some test.cpp file to debug random code
and I have lines that sometimes i don't remove...

About your over question. Orginally in the code I am talking about,
deque is definitely declared in a class. When I comment that line out
valgrind doesn't report anything. So I did a test by calling deque
directly in the simplest possible main program and i get the same error
report. But I will do some tests again tomorrow when I am back at work
that I could send to that thread.

Also I was going to test the same code but by replacing deque (which I
recently started to use) with vector (which i used in my previous
apps).

Thanks -Mark

Jul 6 '06 #3
ma*****@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<Somethingaqueue ?! I am compiling under Linux

for example:
#include <deque>
using namespace std;

int main()
{
deque<inttest;
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/libstd...allocator.html

Tom
Jul 6 '06 #4
Thanks a lot Tom

This is the first time I am really trying to write a serious program
here and I must say that the other person I am developing this project
with and I are learning a lot of stuff on C++. Can't say it is always
fascinating but it certainly shows that I know little about the subject
;-)

I was expecting the library to indeed do something like that but didn't
know how to put a name on it. Now that you explained it to me, I will
look into it.

Thanks again, mark
Tom Widmer wrote:
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/libstd...allocator.html

Tom
Jul 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: stp | last post by:
Hello, I declare the following types: typedef pair<long, string> CEventPair; typedef deque<CEventPair*> EventPairCont;
3
by: Jeremy Lemaire | last post by:
Hello, I am working on cross platform code that is displaying a huge memory leak when compiled on 11.00 HPUX using the aCC -AA flag. It is not leaking on NT, LINUX, Solaris, or HPUX without the...
9
by: R.Z. | last post by:
i was wondering whether it pays off in terms of memory use to maintain lots of empty deques (it would be convenient for my algorithms but memory use is more important). and does the size of a deque...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
4
by: mast2as | last post by:
Hi guys I wrote a short program to test a Tree class... I plan to use it a lot in my application so thought I would do a memory leak check before I start using it. The code seems good to me in a...
9
by: Randy Yates | last post by:
Hi Folks, This may be somewhat off-topic, but it sorta fits. This is a C++ application that will be built using gcc and targeted (via the wonderful wxWidgets library) for both Windoze and...
18
by: happyvalley | last post by:
Hi, basically, the test function get a char pointer, and assigned a string to it. then the string is passed back by the call-by-reference mechanism. in test(), I reallocate some memory for the...
2
by: tikcireviva | last post by:
Hi Guys, I've done a mulithread queue implementation on stl<queue>, my developement environment is on VC6 as well as FC3. Let's talks about the win32 side. The suspected memory leak is find...
1
by: katem | last post by:
Here's my problem: I have a class A that uses new to create objects of class B and push them onto a deque, like this (code stripped down for clarity): void ImageOperations::FormMask() { ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.