![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
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. |
#2
| |||
| |||
|
|
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. |
#3
| |||
| |||
|
|
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. |
#4
| |||
| |||
|
|
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. |
#5
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |