List:MySQL++« Previous MessageNext Message »
From:Matt Dargavel Date:June 22 2006 10:59am
Subject:RE: Query Object Memory Leak?
View as plain text  
To put my penny's worth in, trying it on Visual Studio Express with mysql++
2.0.7 shows the memory usage going up to about 65M as Bill describes (mine
doesn't crash).  

However, turning on memory leak detection
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/ht
ml/vxconenablingmemoryleakdetection.asp) shows no leaks.  I even put a
memory leak in the Query constructor and recompiled mysql++.  My memory leak
showed up, no other one did.  

I'm not sure why the memory usage goes up so high, but it might have
something to do with the fact that the runtime and O/S don't necessarily
return any memory freed up to the general pool straight away (for efficiency
reasons).  I also tried increasing the loop size ten fold, and after the
memory usage got up to about 300M on my machine, Windows started reclaiming
the memory and it had dropped to 14M by the end.

I've included the revised test prog below (note, you shouldn't be using new
to assign to the conn object, as that does cause a memory leak).

	Regards,

		Matt.


#include "stdafx.h"
#include <stdlib.h>
#include <crtdbg.h>
#include "connection.h"
#include "query.h"

void test()
{
	printf("starting test\r\n");

	mysqlpp::Connection conn; // = new mysqlpp::Connection();

	for(int i=0; i <10; i++) 
	{
		mysqlpp::Query myQuery = conn.query();
	} 

	printf("done test\r\n");
}

int _tmain(int argc, _TCHAR* argv[])
{
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	
	test();
	
	return 0;
}

-----Original Message-----
From: Bill K [mailto:reply@stripped] 
Sent: 22 June 2006 02:41
To: plusplus@stripped
Subject: Re: Query Object Memory Leak?

Warren Young wrote:
> Bill K wrote:
>>
>> I am saying that the MS hotfix does not fix the problem I am having 
>> with the query object, like I thought it would.
>
> Okay, thanks for clearing that up.
>
>> MS hotfix fixed the memory leak in basic_iostream (used in fstream 
>> and stringstream, and others) - which I thought may have fixed the 
>> query object since it inherits from ostream. But no.
>
> Okay, but here's another data point for you: I just tried the test 
> program again, and when it crashes it's only using 5 MB.  It can't be 
> a memory leak.
>
> Here, it's crashing when the CRT dereferences a null pointer.  Why the 
> CRT is doing that is the mystery.
>

Crashes, eh? It doesn't crash for me. Adding an "if( !(i%1000) ){ std::cout
<< i << endl;  }" in the loop, I can see it fly through and finish all
million loops, using over 80MB of memory at the end, according to Windows
Task Manager.

I'll have a look at it more tomorrow.

Thanks again.

- Bill


-- 
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:
http://lists.mysql.com/plusplus?unsub=1

Thread
Query Object Memory Leak?Bill K21 Jun
  • Re: Query Object Memory Leak?Warren Young21 Jun
    • Re: Query Object Memory Leak?Bill K21 Jun
      • Re: Query Object Memory Leak?Warren Young21 Jun
        • Re: Query Object Memory Leak?Bill K21 Jun
          • Re: Query Object Memory Leak?Warren Young21 Jun
            • Re: Query Object Memory Leak?Bill K22 Jun
              • RE: Query Object Memory Leak?Matt Dargavel22 Jun
                • Re: Query Object Memory Leak?Bill K22 Jun
                  • Re: Query Object Memory Leak?Jim Langston22 Jun
                • Re: Query Object Memory Leak?Warren Young23 Jun
              • Re: Query Object Memory Leak?Warren Young23 Jun
                • Re: Query Object Memory Leak?Warren Young23 Jun
                  • RE: Query Object Memory Leak?Matt Dargavel23 Jun