Page 1 of 1

using DataContext in multithread

Posted: Tue 16 Jun 2009 03:33
by john88
Hi everyone.
I am develope multithread application whish use connections to PostgreSQL database.

I have some trivial queries like this:

Code: Select all

internal BaseFlightList ExecSearching()
        {

            BaseFlightList flightList = new BaseFlightList(mask.Date);
            DBDataContext context = new DBDataContext();

            try
            {
                try
                {

                    DateTime date = DateTime.Now;
                   

                    var f = from flight in context.fl
                            where (( flight.dat == date )&& (mask.DBAirline != string.Empty ? flight.carrier == mask.DBAirline : true) && ((mask.DBNumber != string.Empty && mask.DBNumber != XMLBase.mUnknown) ? flight.number == mask.DBNumber : true))
                            select flight;
                    if (f.Count() > 0)
                    {
                        foreach (fl FL in f)
                        {
                            flightList.AddRecord(FLToBFR(FL));
                        }
                    }


                }
                catch (Exception ex)
                {
//...
                }

            }
            finally
            {
                if (context != null)
                {
                    context.Connection.Close();
                    context.Dispose();
                }
            }


        }
I founded that my application use a lot of Virtual Memory Space. And it increasing after each query executing.

Than I write some test application where I just create DataConext and Dispose it in cycle.

Code: Select all

 for (int i = 0; i < 100000; i++)
{
            UC.John.DBDataContext.SITABroker.DataContext context = null;
            try
            {
                context = new UC.John.DBDataContext.SITABroker.DataContext();
            }
            finally
            {
                if (context != null)
                {
                    context.Connection.Close();
                    context.Dispose();

                }
            }
}
I founded that memory space not unallocated.
So I know that
However, it is not possible to predict when garbage collection will occur...[MSDN]
But it seems that resources that DataContext used is never releases in my applcation even I use

Code: Select all

 
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
after context.Dispose().

So my question is:
1. If there are some features in using DataContext in multithread applications
2. How solve the problem with memory using increase? I know that I do something wrong, So can you explain me, what?
Thanx

Posted: Tue 16 Jun 2009 10:00
by AndreyR
1. No Devart.Data.Linq.DataContext class instance can be thread-safe, as the System.Data.Linq.DataContext class instance as well.
2. This problem is already fixed in the recent builds of dotConnect, please let us know if the same problem is reproducible in the latest 5.20.33 build.