0

In my .net application, I have used LINQ-to-SQL to get some data from the database. The volume of data is not big at all (10 rows of data). But I constantly caught the "system.outofmemoryException" in my function even thought there is still spare memory in the server. Interestingly, I can still get the data with a ADO function from other pages.

The problem will be fixed once application pool restarts. From time to time, issue happen again. Do you have any clue how I should debug this scenario?

Note: I have used "using" block for all datacontext connection. Literally, All datacontext would be disposed after use.

Below is the code. It is simple.

using (StoreDataContext db = new StoreDataContext(conn)) 
{
     var list = from category in db.ProductCategories 
                select category;

     ddlCategory.DataSource = list.Distinct().ToList();
     ddlCategory.DataTextField = "CategoryName";
     ddlCategory.DataValueField = "CategoryName";
     ddlCategory.DataBind();
}
5
  • 2
    You have memory leaks in your application , you need to test your application through a good memory profiler Commented Aug 2, 2012 at 8:08
  • 1
    I would suggest you post your Linq code; it seems that either your rows are huge or there's something wrong with the Linq query that's causing it to pull back too much data. Commented Aug 2, 2012 at 8:09
  • Could you show us your linq query and model of classes you used in this query? it seems that you take circullar navigation properties Commented Aug 2, 2012 at 8:16
  • Why are you using Distinct? It implies that you're not selecting from master table. Commented Aug 2, 2012 at 8:51
  • Do you need all columns?? if not use select new{ID=category.categoryID,Name=category.categoryName} Commented Aug 2, 2012 at 8:55

2 Answers 2

1

My suggestion would you use memory profiling tool such as JetBrains dotTrace or RedGate's Ants Profiler (their are more in the market)

Personal experience even I had the same issue on my web application and dotTrace traced the poorly written code for me

Sign up to request clarification or add additional context in comments.

2 Comments

I used Ants Profiler and did not find any clue. I found the memory was occupied by a System.LocalDataStoreElemnt[] class. Do you know is this linq related?
@seanbun I have always used dotTrace because it gives you hotspot of every function call made based on the percentage it returned for a funtion, so refactor it to see in next run if its returns better number then previous. In your case it could be Linq so I would suggest is try to use a non-linq code and check for the difference in numbers, thats the best I can suggest
1

Exception thrown when there is not enough memory to continue execution of a program.

In order to view your message, see the OutOfMemoryException constructors.

Reasons :

  1. you have an infinite loop.

  2. You have lot of data, verify your queries sql when you load your context ans entities set.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.