dbTalk Databases Forums  

Re: plz help me.. there is a memory leak..

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Re: plz help me.. there is a memory leak.. in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Denis ERCHOFF
 
Posts: n/a

Default Re: plz help me.. there is a memory leak.. - 01-18-2006 , 02:20 AM






/for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that store data to insert
{
templateQuery.def[i] = receivedVector.at(i);
}/

Replacing //templateQuery// with /query/ help you ?


최 종윤 a écrit :
Quote:
I am making some server program that insert data to mysql 5.0.6
And I am using mysql++-2.0.7.

But there is a memory leak, so let me know how can I avoid this problem.
================================================== ================================================== ====
mysqlpp::Query query = g_dbcon.query();
query << "insert into table_name \
(column_0,column_1,column_2,column_3,column_4,colu mn_5,column_6,column_7,column_8,column_9) \
values(%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q, %9q)";
query.parse();
unsigned int i;
for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that store data to insert
{
templateQuery.def[i] = receivedVector.at(i);
}
//until this, there is no memory leak
query.execute(); // <-------------------after here, this program's memory increasing
//query.execute("a","b","c"); // but if i insert data like this, there is no memory leak..
================================================== ================================================== ====


sorry for my poor English.
Thanks.



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #2  
Old   
Denis ERCHOFF
 
Posts: n/a

Default Re: plz help me.. there is a memory leak.. - 01-18-2006 , 02:46 AM






Sorry, no more idea.

Control each value copied from the receivedVector to the query, maybe
one of these values returns a bad thing/pointer.
What kind of value handle your vector ? What is it his definiton ?

최 종윤 a écrit :
Quote:
oh, that is my problem.
yes query is right but it is not solution
that is just copy & paste problem from source to mail
original function looks like this

int setColumnValue( mysqlpp::Query& templateQuery )
{
unsigned int i;
for(i=0;i<receivedVector.size();i++)
{
templateQuery.def[i] = receivedVector.at(i);
}
return 0;
}

can you give me more help?

-----Original Message-----
From: Denis ERCHOFF [mailto:d_erchoff (AT) hotmail (DOT) com]
Sent: Wednesday, January 18, 2006 5:20 PM
To: 최 종윤
Cc: plusplus (AT) lists (DOT) mysql.com
Subject: Re: plz help me.. there is a memory leak..

/for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that store data to insert {
templateQuery.def[i] = receivedVector.at(i); }/

Replacing //templateQuery// with /query/ help you ?


최 종윤 a écrit :

I am making some server program that insert data to mysql 5.0.6 And I
am using mysql++-2.0.7.

But there is a memory leak, so let me know how can I avoid this problem.
================================================== ====================
==================================
mysqlpp::Query query = g_dbcon.query(); query << "insert into
table_name \
(column_0,column_1,column_2,column_3,column_4,colu mn_5,column_6,column_7,column_8,column_9) \
values(%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q,
%9q)"; query.parse(); unsigned int i;
for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that
store data to insert {
templateQuery.def[i] = receivedVector.at(i); } //until this, there
is no memory leak
query.execute(); // <-------------------after here, this program's memory increasing
//query.execute("a","b","c"); // but if i insert data like this, there is no memory leak..
================================================== ====================
==================================


sorry for my poor English.
Thanks.




--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Drew Vogel
 
Posts: n/a

Default Re: plz help me.. there is a memory leak.. - 01-18-2006 , 08:31 AM



What happens when you run this through Valgrind?

Drew Vogel



최 종윤 wrote:

Quote:
that vector is declared like this

std::vector<std::string> receivedVector;

and is used like this.

receivedVector.push_back(str.substr(blabla... )); //str is some string

well, but
in the source,
if I do comment query.execute(), this is no memory leak, (query.preview() also make memory leak)
but if I do not comment that, the memory of server program is increasing when handle more data.

anyway, Thank you very much!!




-----Original Message-----
From: Denis ERCHOFF [mailto:d_erchoff (AT) hotmail (DOT) com]
Sent: Wednesday, January 18, 2006 5:46 PM
To: 최 종윤
Cc: plusplus (AT) lists (DOT) mysql.com
Subject: Re: plz help me.. there is a memory leak..

Sorry, no more idea.

Control each value copied from the receivedVector to the query, maybe one of these values returns a bad thing/pointer.
What kind of value handle your vector ? What is it his definiton ?

최 종윤 a écrit :


oh, that is my problem.
yes query is right but it is not solution that is just copy & paste
problem from source to mail original function looks like this

int setColumnValue( mysqlpp::Query& templateQuery ) {
unsigned int i;
for(i=0;i<receivedVector.size();i++)
{
templateQuery.def[i] = receivedVector.at(i);
}
return 0;
}

can you give me more help?

-----Original Message-----
From: Denis ERCHOFF [mailto:d_erchoff (AT) hotmail (DOT) com]
Sent: Wednesday, January 18, 2006 5:20 PM
To: 최 종윤
Cc: plusplus (AT) lists (DOT) mysql.com
Subject: Re: plz help me.. there is a memory leak..

/for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that store data to insert {
templateQuery.def[i] = receivedVector.at(i); }/

Replacing //templateQuery// with /query/ help you ?


최 종윤 a écrit :



I am making some server program that insert data to mysql 5.0.6 And I
am using mysql++-2.0.7.

But there is a memory leak, so let me know how can I avoid this problem.
================================================== ===================
=
==================================
mysqlpp::Query query = g_dbcon.query(); query << "insert into
table_name \
(column_0,column_1,column_2,column_3,column_4,colu mn_5,column_6,column_7,column_8,column_9) \
values(%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q,
%9q)"; query.parse(); unsigned int i;
for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that
store data to insert {
templateQuery.def[i] = receivedVector.at(i); } //until this,
there is no memory leak
query.execute(); // <-------------------after here, this program's memory increasing
//query.execute("a","b","c"); // but if i insert data like this, there is no memory leak..
================================================== ===================
=
==================================


sorry for my poor English.
Thanks.







--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Drew Vogel
 
Posts: n/a

Default Re: plz help me.. there is a memory leak.. - 01-19-2006 , 08:15 AM



"Still reachable" blocks are normal, but not good. A memory leak is when
you allocate memory with new/malloc() and then reassign the pointer to
another memory address before calling delete/free() on it. Once you
don't have a pointer to the memory, it is "unreachable" or "leaked",
because there is no way that memory can be deallocated until the program
exits and your standard library cleans up for you. e.g.

char* cp = 0;
cp = new char[100];
cp = new char[200]; // we just leaked the 100 chars allocated in the
previous line.


See this section of the manual:

http://valgrind.org/docs/manual/mc-m...c-manual.leaks






최 종윤 wrote:

Quote:
Valgrind was very easy, and I do that
I reduced the loop to 10 times, and the result is like this.
and I think that there is no memory leak but valgrind report that there is still reachable blocks.
Is this normal ?
Thank you.

Choi jong-yoon

[kikiki@karen01 LogTrac]$ /raiders/kikiki/valgrind/bin/valgrind --show-reachable=yes ./Test
==13002== Memcheck, a memory error detector.
==13002== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==13002== Using LibVEX rev 1367, a library for dynamic binary translation.
==13002== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==13002== Using valgrind-3.0.1, a dynamic binary instrumentation framework.
==13002== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==13002== For more details, rerun with: -v
==13002==
Connecting to database server...
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
query : insert into table_name (column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) values(%0q, %1q, %2q, %3q, '%4,%5', %6q)
==13002==
==13002== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 48 from 1)
==13002== malloc/free: in use at exit: 39320 bytes in 12 blocks.
==13002== malloc/free: 157 allocs, 145 frees, 108097 bytes allocated.
==13002== For counts of detected errors, rerun with: -v
==13002== searching for pointers to 12 not-freed blocks.
==13002== checked 809368 bytes.
==13002==
==13002== LEAK SUMMARY:
==13002== definitely lost: 0 bytes in 0 blocks.
==13002== possibly lost: 0 bytes in 0 blocks.
==13002== still reachable: 39320 bytes in 12 blocks.
==13002== suppressed: 0 bytes in 0 blocks.

-----Original Message-----
From: 최 종윤 [mailto:kikiki (AT) neowiz (DOT) com]
Sent: Thursday, January 19, 2006 8:30 PM
To: Drew Vogel
Cc: plusplus (AT) lists (DOT) mysql.com
Subject: RE: plz help me.. there is a memory leak..

I made a test program to test this.
The program is on the redhat 9.(kernel : 2.4.20) I get the information from command "top" , and the result was like this.

â‘*
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
4937 kikiki 21 0 2672 2672 2304 S 0.0 0.0 0:00 3 Test

but after 100000 Loop, the information is changed like this.

â‘¡
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
4937 kikiki 25 0 18384 17M 2340 S 0.0 0.4 0:19 2 Test

As you can see, the SIZE and RSS factor is increased.
And I thought this could be a problem if I made this as a server program.
I have never used Valgrind before, so I would try that (I will report the result tomorrow).

Let me know abou my mistake.
Thank you.

- Choi Jong-Yoon


Test Program source
--------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h
#include <mysql++.h
#include <unistd.h
#include <iostream

int main (int argc, char *argv[])
{

mysqlpp::Connection g_dbcon; //! variable to connect mysql and sended to thread

try {
std::cout << "Connecting to database server..." << std::endl;
g_dbcon.connect("xxx", "xxx", "xxx", "xxx");
}
catch (std::exception& er) {
std::cout << "Connecting to database server failed" << er.what() << std::endl;
return -1;
}

std::string user_input;
getline(std::cin,user_input,'\n'); //here, checked memory by comman "top" -â‘*

mysqlpp::Query query = g_dbcon.query();

for(int j=0;j<100000;j++){

try{

std::string sql = "insert into table_name \
(column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) \
values(%0q, %1q, %2q, %3q, '%4,%5', %6q)";
query << sql;
query.def[(unsigned int)0] = "a";
query.def[(unsigned int)1] = "b";
query.def[(unsigned int)2] = "c";
query.def[(unsigned int)3] = "d";
query.def[(unsigned int)4] = "e";
query.def[(unsigned int)5] = "f";
query.def[(unsigned int)6] = "g";
query.parse(); //If I comment this line, the program's memory doesn't change
std::cout << "query : " << query.preview() << std::endl;//If I comment this line, the program's memory doesn't change
//query.reset(); //this doesn't make difference.
//query.execute();
}
catch (const mysqlpp::BadQuery& er) {
// Handle any query errors
std::cerr << "Query error: " << er.what() << std::endl;
return -1;
}
catch (const mysqlpp::BadConversion& er) {
std::cerr << "Conversion error: " << er.what() << std::endl ;
return -1;
}
catch (const mysqlpp::Exception& er) {
std::cerr << "Error: " << er.what() << std::endl;
return -1;
}catch (std::exception& er) {
std::cerr << "Error: " << er.what() << std::endl;
return -1;
}


}
getline(std::cin,user_input,'\n'); //here, checked memory by comman "top" -â‘¡
return 0;
}

-----Original Message-----
From: Drew Vogel [mailto:dvogel (AT) intercarve (DOT) net]
Sent: Wednesday, January 18, 2006 11:46 PM
Cc: plusplus (AT) lists (DOT) mysql.com
Subject: Re: plz help me.. there is a memory leak..

What happens when you run this through Valgrind?

Drew Vogel



최 종윤 wrote:



that vector is declared like this

std::vector<std::string> receivedVector;

and is used like this.

receivedVector.push_back(str.substr(blabla... )); //str is some string

well, but
in the source,
if I do comment query.execute(), this is no memory leak,
(query.preview() also make memory leak) but if I do not comment that, the memory of server program is increasing when handle more data.

anyway, Thank you very much!!




-----Original Message-----
From: Denis ERCHOFF [mailto:d_erchoff (AT) hotmail (DOT) com]
Sent: Wednesday, January 18, 2006 5:46 PM
To: 최 종윤
Cc: plusplus (AT) lists (DOT) mysql.com
Subject: Re: plz help me.. there is a memory leak..

Sorry, no more idea.

Control each value copied from the receivedVector to the query, maybe one of these values returns a bad thing/pointer.
What kind of value handle your vector ? What is it his definiton ?

최 종윤 a écrit :




oh, that is my problem.
yes query is right but it is not solution that is just copy & paste
problem from source to mail original function looks like this

int setColumnValue( mysqlpp::Query& templateQuery ) {
unsigned int i;
for(i=0;i<receivedVector.size();i++)
{
templateQuery.def[i] = receivedVector.at(i);
}
return 0;
}

can you give me more help?

-----Original Message-----
From: Denis ERCHOFF [mailto:d_erchoff (AT) hotmail (DOT) com]
Sent: Wednesday, January 18, 2006 5:20 PM
To: 최 종윤
Cc: plusplus (AT) lists (DOT) mysql.com
Subject: Re: plz help me.. there is a memory leak..

/for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that store data to insert {
templateQuery.def[i] = receivedVector.at(i); }/

Replacing //templateQuery// with /query/ help you ?


최 종윤 a écrit :





I am making some server program that insert data to mysql 5.0.6 And I
am using mysql++-2.0.7.

But there is a memory leak, so let me know how can I avoid this problem.
================================================== ===================
=
==================================
mysqlpp::Query query = g_dbcon.query(); query << "insert into
table_name \
(column_0,column_1,column_2,column_3,column_4,colu mn_5,column_6,column_7,column_8,column_9) \
values(%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q,
%9q)"; query.parse(); unsigned int i;
for(i=0;i<receivedVector.size();i++) //receivedVector is Vector that
store data to insert {
templateQuery.def[i] = receivedVector.at(i); } //until this,
there is no memory leak
query.execute(); // <-------------------after here, this program's memory increasing
//query.execute("a","b","c"); // but if i insert data like this, there is no memory leak..
================================================== ===================
=
==================================


sorry for my poor English.
Thanks.













--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #5  
Old   
Chris Frey
 
Posts: n/a

Default Re: plz help me.. there is a memory leak.. - 01-26-2006 , 06:30 PM



On Thu, Jan 19, 2006 at 08:29:40PM +0900, ??? ?????? wrote:
Quote:
mysqlpp::Query query = g_dbcon.query();

for(int j=0;j<100000;j++){

try{

std::string sql = "insert into table_name \
(column_a,column_b,column_c,column_d,column_e,colu mn_f,column_g) \
values(%0q, %1q, %2q, %3q, '%4,%5', %6q)";
query << sql;
query.def[(unsigned int)0] = "a";
query.def[(unsigned int)1] = "b";
query.def[(unsigned int)2] = "c";
query.def[(unsigned int)3] = "d";
query.def[(unsigned int)4] = "e";
query.def[(unsigned int)5] = "f";
query.def[(unsigned int)6] = "g";
query.parse(); //If I comment this line, the program's memory doesn't change
std::cout << "query : " << query.preview() << std::endl;//If I comment this line, the program's memory doesn't change

To determine if this is really a memory leak, you need to make sure that
you're freeing the memory. In this case, any memory allocated by Query
will not be freed, since it is on the stack and doesn't free until after
main() returns.

You might try moving the Query object inside the for loop:

for(int j=0;j<100000;j++) {
mysqlpp::Query query = g_dbcon.query();
...
}
// query goes out of scope here and is freed

If there is still a problem, then there might be a memory leak.

- Chris


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.