using DataContext in multithread

using DataContext in multithread

Postby john88 » Tue 16 Jun 2009 03:33

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
john88
 
Posts: 1
Joined: Tue 16 Jun 2009 02:49

Postby AndreyR » Tue 16 Jun 2009 10:00

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.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16


Return to dotConnect for PostgreSQL