Memory leak problem with datacontext

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
dilbert
Posts: 68
Joined: Tue 28 Apr 2009 10:11

Memory leak problem with datacontext

Post by dilbert » Tue 08 Dec 2009 01:41

You have announced in some previous versions that you have managed to fix memory leak problems.
However, we are currently using the latest version (MySQL 5.50.57) and we deployed our application last week. After a few hours our servers ran into memory leak each time.

After some investigation we found out the problem is caused by datacontext which were never collected by Garbage-collector.

We have solved this problem by explicit disposing of the DataContext (by "using" statement). The problem with memory leak has never appeared again.

Of course, I understand that disposing some large objects belongs to good manners - at least. However, it should not be necessary - I assured this on MSDN articles concerning .Net LinqToSql.
So I supppose it is quite a serious bug in Devart LingToSql library.

I would really appreciate if you can check this issue responsibly.
Thank you in advance.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 08 Dec 2009 13:01

Could you please describe the scenario you are using DataContexts in?
I suppose that you have a number of objects queried from the database.
Then you probably modify these objects in some way and create a new instance of DataContext to submit the changes.
If these objects are not disposed, the reference to context is held.
By the way, Microsoft decleares DataContext as the class designed to be used with the 'unit of work' pattern here:
http://msdn.microsoft.com/en-us/library ... ntext.aspx

dilbert
Posts: 68
Joined: Tue 28 Apr 2009 10:11

Post by dilbert » Tue 08 Dec 2009 13:45

AndreyR wrote:Could you please describe the scenario you are using DataContexts in?
I suppose that you have a number of objects queried from the database.
Then you probably modify these objects in some way and create a new instance of DataContext to submit the changes.
Not at all. We do not use anything like 'attach' methods etc.

Respectively, we use scenario which is close to the one described in this article:
http://www.west-wind.com/weblog/posts/246222.aspx
in the section "Create a per Business Object instance of DataContext".

It means, the datacontext is used usually for one or two queries. And if some objects are modified, they are always submitted by the same datacontext.

I can send you a simple test application, which we used for the investigation. This application do nothing more than create a business object with datacontext (BO has no other objects) and one simple query. This is run on the page which is executed in the iteration cycle.
If we dispose the datacontext after each query, everything is OK, otherwise allocated memory is still rising.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 09 Dec 2009 15:24

Thank you for the clarification. Could you please send me (support * devart * com, subject "LINQ: Disposing context") the mentioned project?
This will speed up the investigation.

Post Reply