LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-12-2005, 02:07 PM   #1
BorisMcHack
Member
 
Registered: May 2004
Location: uk
Distribution: debian sarge
Posts: 65

Rep: Reputation: 15
<string> mem leak help


Hi,

I've recently started using ccmalloc to detect memory leaks in my programs, and the biggest source of leaks I find seems to be the string class in c++.

My prog uses quite a lot of string += "blah" like stuff, and so the memory leaks are reaching quite high levels, imho.

Several questions:

1) Alternative string class? (I tried glib g_string, but that seems to have similar probs)

2) Get ccmalloc to ignore string ?

3) update my distro?

4) workarounds? I tried things like string.erase() to no avail.

In the simple program below, no memory de-allocation appears to be happening at all:

#include <iostream>
#include <string.h>
#include <string>

using namespace std;

int main(void)
{
string quack = "Hello";
cout << "\nstring quack = " << quack << "\n";
}


g++ --version
g++ (GCC) 3.3.4 (Debian 1:3.3.4-13)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ccmalloc g++ -g3 str.cc -o str
[ccmalloc] version .. 0.4.0
[ccmalloc] prefix .. /usr
[ccmalloc] compilers .. gcc g++ g++-2.95
[ccmalloc] wrapper .. /usr/lib/ccmalloc-g++.o
g++ -g3 str.cc -o str /usr/lib/ccmalloc-g++.o -lccmalloc -ldl

./str

.---------------.
|ccmalloc report|
=======================================================
| total # of| allocated | deallocated | garbage |
+-----------+-------------+-------------+-------------+
| bytes| 960 | 0 | 960 |
+-----------+-------------+-------------+-------------+
|allocations| 1 | 0 | 1 |
+-----------------------------------------------------+
| number of checks: 1 |
| number of counts: 1 |
| retrieving function names for addresses ... done. |
| reading file info from gdb ... done. |
| sorting by number of not reclaimed bytes ... done. |
| number of call chains: 1 |
| number of ignored call chains: 0 |
| number of reported call chains: 1 |
| number of internal call chains: 1 |
| number of library call chains: 0 |
=======================================================
*100.0% = 960 Bytes of garbage allocated in 1 allocation
| | 0x40128dc6 <???>
| | 0x0804939a <main> str.cc:9
| | 0x400ae4a9 <???>
| | 0x400b1d50 <???>
| | 0x400b0ff8 <???>
| | 0x400ab668 <???>
| | 0x400ab96d <???>
| | 0x400aba5b <???>
| | 0x400bf2ee <???>
| `-----> 0x0804ec47 <malloc>
`------------------------------------------------------

Last edited by BorisMcHack; 04-12-2005 at 02:10 PM.
 
Old 04-12-2005, 04:24 PM   #2
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
While you are using g++ 3.3.4, ccmalloc seems to report "g++-2.95 " there. Is it a problem with ccmalloc itself?
 
Old 04-13-2005, 12:35 AM   #3
BorisMcHack
Member
 
Registered: May 2004
Location: uk
Distribution: debian sarge
Posts: 65

Original Poster
Rep: Reputation: 15
I think that is just one of the compilers it supports, rather than mis-reporting usage of gcc-2.95. Possibly ccmalloc needs the debug info so that it can tell whats going on in libstdc++5? I've installed the libstdc++5 debug libs, just trying to figure out how to link to them :/

I saw another thread mentioning valgrind (http://valgrind.org/), I may give that a try also.
 
Old 04-13-2005, 01:11 AM   #4
BorisMcHack
Member
 
Registered: May 2004
Location: uk
Distribution: debian sarge
Posts: 65

Original Poster
Rep: Reputation: 15
aparently its because of the way the STL allocates & deallocates memory, which fools memory profilers:

http://lists.debian.org/debian-gcc/2.../msg00090.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash way to tell if String is in String tongar Programming 3 06-16-2005 06:59 AM
SuSE Pro - Mem leak? mikedeatworld Linux - Software 6 10-26-2004 01:34 PM
C....Search a string for a string Scrag Programming 4 06-14-2004 04:15 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM
Mem Questions?? CragStar Linux - General 2 08-06-2001 03:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration