Solved

MySQL question - memory leaks.  how to resolve?

Posted on 2006-11-08
4
1,436 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now