Answer the question
In order to leave comments, you need to log in
Where does memory go in .NET C#?
Probably a stupid question from the outside ... but I encountered this for the first time, when examining the performance of a C # program in Process Explorer, memory is slowly leaking.
The patient is launched under the Visual Studio debugger, how can you determine where and what the memory goes to and why it cannot be freed?
Answer the question
In order to leave comments, you need to log in
dottrace.memory?
ps what is leaking? GC.Collect() releases "excess" or not? calls of any unmanaged code or processes - is there?
The GS Handles counter constantly changes and grows 500 - 600 , 522 - 700 , 600 - 839 , 993 - 1100.
On the form, when updating the DataTableGrid, Dictionary <string,string> is used via the DataSource.
After studying the problem, the following was revealed when writing data to the database through the ODBC Manager, there are large jumps in memory up to 30 megabytes, which are subsequently cleared more slowly than the planned access to the database. A total of 30 megabytes quickly turns into 400. But after the database access is stopped, all memory is gradually cleared.
The function of writing to the database has the following form, which is frequently accessed
public static int ExecuteNonQuery(string query)
{
int ret = 0;
// return ret; если раскоментировать употребление памяти не увеличивается
lock (Lock)
{
try
{
using (OdbcConnection Connection = new OdbcConnection(ConnectionString))
{
Connection.Open();
if (Connection.State == System.Data.ConnectionState.Open)
{
using (var command = new OdbcCommand(query, Connection))
{
ret = command.ExecuteNonQuery();
}
}
Connection.Close();
//OdbcConnection.ReleaseObjectPool();
}
OdbcConnection.ReleaseObjectPool();
}
catch (Exception e)
{
Console.WriteLine("ExecuteNonQuery=" + e.Message);
}
}
return ret;
}
public static void AddRecordsInArhiveAsync(ushort Code, bool NewData, DateTime Now, bool Finish = false)
{
Thread _trdAddRecords = new Thread(
delegate()
{
lock (LockThis)
AddRecordsInArhive(Code, NewData, Now, Finish); // Внутри вызывается функция ExecuteNonQuery(string query)
}
);
_trdAddRecords.Priority = ThreadPriority.Normal;
_trdAddRecords.Start();
}
public static void AddRecordsInArhiveSync(ushort Code, bool NewData, DateTime Now, bool Finish = false)
{
lock (LockThis)
AddRecordsInArhive(Code, NewData, Now, Finish);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question