Solved

MySQL question - memory leaks.  how to resolve?

Posted on 2006-11-08
4
1,469 Views
Last Modified: 2012-06-27
info..

dev env     =  VS C# .Net 2003
version     =   MySQL 5.0.27-community-nt via named pipe
connector =    MySQL Connector Net 1.0.8
admin       =   MySQL Admin 1.2.5 rc

My C# app has memory leaks.   From the App..  I make function calls to referenced C++ dlls from inside the VS C# .Net env, however I'm confident that the leaks are not because of C++ code in the dlls not releasing memory.  I reset objects to null and make use of garbage collection fairly well..  so..  I think the problem is with MySQL because recently...  after re-installing MySQL to the latest version 5.0.27 I noticed that the pagefile was reduced by 50% at the startup of the app...   which was a nice surprise.    Not sure if I just changed the settings, thus causing the reduction..  but in any case..

After startup, it is my gut feeling that MySQL is causing the pagefile to grow 2 to 4 MB  every few secs.    I would gladly post my database connectivity code if that would help to find a solution, however for the time being, can anyone direct me to links, or documentation that can help me troubleshoot leaks when running MySQL in the .Net environment?  

I make attempts to release the connection where i think it's necessary as follows:

public virtual void releaseConnection(MySqlConnection connection)
{
    try
    {
         connection.Close();
         connection.Dispose();
     }
     catch (Exception ex)
     {
          WriteStackTrace(ex, Console.Error);
     }
}

Note:  In the Task Manager, when machine is at rest.. with no Apps running..      MySQL looks as follows:

Image Name               Mem Usage              VM Size               Handles            Threads
mysqld-nt.exe               15,392 K                  84,9565 K             4,457                15

The mysqld-nt.exe stays relatively the same size, however....  when my VS C# App is then running, the App's exe continues to grow in size, possibly because I'm not using MySQL properly in order for the garbage collection to release memory that MySQL is utilizing.    Any input appreciated here.   More specific info can be provided upon request.    Thanks.
0
Comment
Question by:lblinc
  • 2
4 Comments
 
LVL 12

Assisted Solution

by:AdrianSRU
AdrianSRU earned 100 total points
ID: 17900025
Can you post a section of code where you are executing a query?  That's my guess for where the problem is.  You can test that by putting a simple query in a loop to execute a few thousand times and see if that increases the memory usage.


--Adrian
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 400 total points
ID: 17902238
Hi,

A few pointers firstly I am assuming when you installed the new version of mysql you reverted back to the default configuation - this is not particularly fast.  You would be best tuning it for what you are doing - ie the table types, how much ram is associated - what processors you are using

http://dev.mysql.com/books/hpmysql-excerpts/ch06.html
dev.mysql.com/doc/refman/5.0/en/optimization.html

the other thing is that you mention that you are disposing of the connection - but if you have connection pooling the connection is not closed at all - and will not release resources

if you add
Pooling=False;
to your connection string - it will disable connection pooling - meaning that when you close the connection it is actually closed
0
 

Author Comment

by:lblinc
ID: 17907516
these are helpful in my troubleshooting efforts, thanks.    i will need a bit more time researching things and trying to narrow it down as to where leaks are at..       please allow me a day or two for debugging and tweaking the mysql settings to get back with more info.    i truly appreciate the advice.    

you know, i did notice one thing in particular in another post that may be relevant in my case, as follows:      gregoryyoung mentioned the possibility of an exception making a close not occur, and I need to look into this possibilty of this occurance in my try{} catch{}  finally{}  code blocks.

i think it was from this other post..

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21403670.html?query=dispose&topics=327

0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17912132
you could always test this by having a finally after any try catches you have - checking if the connection is open - and if it is then throwing another error
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question