473,493 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 4789
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
6181
by: stp | last post by:
Hello, I declare the following types: typedef pair<long, string> CEventPair; typedef deque<CEventPair*> EventPairCont;
3
4649
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
3707
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
3390
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
438
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
3479
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
9048
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
5276
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
2361
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() { ...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.