Memory Leak from a loop inside thread.
Hi everybody,
I am having memory leak problem from inside the thread. I have create this thread which does a monitoring on certain activity. This thread may run for 3/4 days. I have put a While loop inside the thread which is making the thread to do the same monitoring task again and again. This thread also interacts with the database too.
Environment :
language : C#
Databse : SQLite (its a small database and is open source).
I have tried different methods to reduce the memory leak problem, such as:
-Disposing all the class when not in used.
-called the GC forcefully.
-closing unmanaged resources, etc.
Please try to help me solve this problem.
Thank you,
shakti
shakti shresthaPosted Jun 6, 2007, 9:36 PM
private void StartRealTrading() { string CurrencyPair = String.Empty; SimulationData Simulate = new SimulationData(); DataRow[] dRows; string PossessedCurrencyPair = string.Empty; bool IsPossessed = false; DataTable DtPossessed = new DataTable(); int cnt = 0; try { while (true) { if (cnt > 100) { GC.Collect(); cnt = 0; } cnt++; if (!_Start) break; try { // This function check the information from Database if (!GetDBPossessedCurrency(ref PossessedCurrencyPair)) this.AddOrderInformation = true; Thread.Sleep(500); // This Function dequeues object from queue and stores it into datatable if the AddOrderInformation ==true. DequeueOrderInformation(); //check if start date has crossed or not. if (DateTime.Now < mUsrSetting.StartDate) continue; /* check if end date has crossed or not. * if end date is reached the stop the Auto Run */ if (DateTime.Today > mUsrSetting.EndDate) break; //check if any currency pair exists for monitoring or not. dRows = dtOrderInfo.Select("DoMonitoring = 1 "); // 1= do monitoring ,, 0 = don't do monitoring if (dRows == null || dRows.Length == 0) { continue; } } catch (ThreadAbortException) { break; } catch (Exception ex) { this.mELog.WriteError("StartRealTrading1", ex, false); } //foreach (DataRow dRow in dtOrderInfo.Rows) for(int i=0;iJan MontanoPosted Jun 6, 2007, 2:59 AM