List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:September 13 2008 12:06pm
Subject:Re: Memory will be exhausted when a minor change is made in "multiquery.cpp"
View as plain text  
On Sep 12, 2008, at 1:31 AM, weidong shen wrote:

> b. Add one instruction into below method/function. The memory will  
> increase.
> *static void
> print_row(IntVectorType& widths, Row& row)
> {
> cout << "  |" << setfill(' ');
> for (size_t i = 0; i < row.size(); ++i) {
>        long lTmp = row[i];
>  cout << " " << setw(widths.at(i)) << row[i] << " |";
> }
> cout << endl;
> }*
> **

When I try this, I get a BadConversion exception, because not all  
row[i] can be converted to long without losing data.

Since I assume you actually tried this, you must be using a different  
version of MySQL++ than I am, which is the current svn version.  That  
behavior hasn't changed since at least v3.0, so I guess you're using  
v2.x or v1.x of MySQL++?  Have you tried upgrading?

I made my own change to MySQL++'s example, based on yours.  (See patch  
below.)  It just wraps the row[i] conversion attempt in an exception  
handler and puts the main query logic into a long-running loop so it  
will run long enough to watch memory use with a process monitor.

If you run it, you should see memory use rise, yes, but then stabilize  
after a second or two.  That's not a leak, it's just the way modern  
OSes work.

I've tried this on both OS X and on Linux.  I didn't bother trying it  
on Windows because OS-specific leaks are rare.

Index: examples/multiquery.cpp
===================================================================
--- examples/multiquery.cpp	(revision 2358)
+++ examples/multiquery.cpp	(working copy)
@@ -61,6 +61,11 @@
  {
  	cout << "  |" << setfill(' ');
  	for (size_t i = 0; i < row.size(); ++i) {
+		try {
+			long lTmp = row[i];
+		}
+		catch (BadConversion& e) {
+		}
  		cout << " " << setw(widths.at(i)) << row[i] << " |";
  	}
  	cout << endl;
@@ -153,6 +158,7 @@
  			return 1;
  		}

+		for (int qq = 0; qq < 10000; ++qq) {
  		// Set up query with multiple queries.
  		Query query = con.query("DROP TABLE IF EXISTS test_table; "
  				"CREATE TABLE test_table(id INT); "
@@ -185,6 +191,7 @@
  		cout << "Query: " << query << endl;
  		print_multiple_results(query);
  #endif
+		}

  		return 0;
  	}

Thread
Memory will be exhausted when a minor change is made in "multiquery.cpp"weidong shen12 Sep
  • Re: Memory will be exhausted when a minor change is made in "multiquery.cpp"Warren Young13 Sep
Re: Memory will be exhausted when a minor change is made in "multiquery.cpp"weidong shen16 Sep
  • Re: Memory will be exhausted when a minor change is made in "multiquery.cpp"weidong shen16 Sep
  • Re: Memory will be exhausted when a minor change is made in "multiquery.cpp"Warren Young17 Sep