Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I believe the problem below is related to BOOST threads versus .NET threads even though I was able to isolate the leak to a single line. When I run the same code with .NET threads using ADO .NET directly, my memory usage is about 45 MB versus > 1 GB before.

I have a block on code that uses 25 MB of memory when run single-threaded. When I have it run with 16 threads, the memory usage grows to 200MB in 5 minutes and to above 1GB eventually.

I've narrowed down the leak to ADO . NET code that executes an insert query given two inputs Query_Text and Connection_String are char * const. The function is inside dll and is called by a C++ dll without CLR, so that I do not need to use .NET threads (which is incompatible with other code).

C#
System::Data::OleDb::OleDbConnection ^db_Conn;
try {
    db_Conn=gcnew System::Data::OleDb::OleDbConnection(gcnew System::String(Connection_String));
        System::Data::OleDb::OleDbCommand ^db_Command=gcnew
    System::Data::OleDb::OleDbCommand(gcnew System::String(Query_Text), db_Conn);
        db_Conn->Open();
        db_Command->ExecuteNonQuery();
        db_Conn->Close();
}
catch(System::Data::OleDb::OleDbException ^mySqlEx) {
    if (db_Conn)
        db_Conn->Close();
}


Can you tell me what I am doing wrong? This is the worst memory leak I have ever had. Do I need to call gc.collect() after every 100 calls or something?
Posted
Updated 22-Sep-10 18:26pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900