473,659 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with memory leak problem with datatype string in C++

1 New Member
Hi, i have some questions regarding the use of datatype string in C++. I use g++ compiler and also use .ccmalloc to test for the memory leak.

Here is a simple program that i have wrote which ccmalloc reports that there is a memory leak:

line 1: #include <iostream>
line 2:
line 3: using namespace std;
line 4:
line 5: int main(int argc, char **argv)
line 6: {
line 7: string test;
line 8: test = "Klungkung" ;
line 9: test.clear();
line10: return 0;
line11: }

I compile it like this:
g++ -c -g -Wall main.cpp
./ccmalloc -o maintest.exe main.o
./maintest.exe

Output display like this:

.---------------.
|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
| |
| | 0x42015574 in <???>
| |
| | 0x08049209 in <main>
| | at main.cpp:8
| |
| | 0xb7f9b87c in <???>
| |
| | 0xb7f9ee23 in <???>
| |
| | 0xb7f9aacd in <???>
| |
| | 0xb7f9e2a8 in <???>
| |
| | 0xb7f982ac in <???>
| |
| | 0xb7f9873d in <???>
| |
| | 0xb7f98831 in <???>
| |
| | 0xb7fabe9e in <???>
| |
| `-----> 0x08056047 in <malloc>
| at src/wrapper.c:318
|
`------------------------------------------------------

If i uncomment the code at line 8, ccmalloc returns no garbage (no memory leak).

Does anyone could help me with this?

Thank You very much

Toni
Aug 18 '06 #1
0 1407

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3846
by: Greg Baker | last post by:
I don't know what standard protocol is in this newsgroup. Am I allowed to post code and ask for help? I hope so.. :) Here's my problem: I am trying problem 127 of the valladolid online contests (http://online-judge.uva.es/p/v1/127.html). The program I wrote seems to work fine, but it takes way too much memory to run. I am not that good at programming C++, unfortunately, so I can't seem to find my memory leak. As far as I can tell,...
5
2671
by: Trokey | last post by:
I am making interop calls to an object in a .NET component from a C++ program and am leaking memory... the following is some sample code: //////////////////////////////////////// // .NET component (Test) //////////////////////////////////////// // interface
23
4545
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
10
2747
by: mark | last post by:
I have a simple windows application that has a function to read a csv file and enter the values into an array A as double(,). Also, an instance of form 2 (which has a DataGrid) is created and the values of A are used to populate the grid via a DataView. The instance of form2 is called Matrix_A . The basic layout is as follows: #Region "Globals Dim A As Double(,) Dim Matrix_A As form2 #End Region
8
8532
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of each object within my JS app to help locate my problem? Thanks
7
2549
by: Fernando Barsoba | last post by:
Hi, After following the advice received in this list, I have isolated the memory leak problem I am having. I am also using MEMWATCH and I think it is working properly. The program does some calculations and stores elements in a list. After that, a sorting algorithm is used over that list. Two functions are called before the sorting process:
4
4453
by: lars.uffmann | last post by:
I just reduced a nasty and hard to pin-down memory leak (according to mtrace() under SuSE 9.3 to a very simple example file and would like to know what the error is about, and whether it maybe is a bug in the basic_string-template, or a bug / problem with mtrace, or something else - and if other people can reproduce it - possibly under non-SuSE-distributions. Using g++ to compile memLeak.cpp with gnu c compiler 3.3.5, the following...
8
8316
by: vidya.bhagwath | last post by:
Hello Experts, I am using std::string object as a member variable in one of the my class. The same class member function operates on the std::string object and it appends some string to that object. My sample code is as follows. ..h file content---------- #include <stdio.h>
1
4879
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
I may have painted myself into a corner with GenerateInMemory=true. My app need a custom user step. Users want to code (sort of - they are not programmers) some refinements to a search procedure. They can concoct a moderately complex boolean expression, and that suffices. I will take their statements, add top and bottom text, and now I can do a CodeDom compile. I generate an assembly via CodeDom with GenerateInMemory. I make a...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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 we have to send another system
2
1978
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.