Linq and higj use of memory

Posted on 2011-02-23
Last Modified: 2012-05-11

   I`ve writtern the code above and when I try upload more than 100K records the RAM goes from 2.7G to to 6G. Is the garbage collection not working well? Is my cod ewrong? I can't dispose the objects...

  Marco Castro
foreach (var item in entity.LinqQuery.ToList()))
  OLAP_VENDAS olapv = new OLAP_VENDAS();
  olapv.VENDAS = new Misc().GenID("OLAP_VENDAS");
  olapv.QT_CONSIG = item.EnvioConsignacao;
    entity.AddObject(olapv.GetType().Name, olapv);
    if (i++ > 500)
      // It connects to the database again
      entity = ActiveEntity.GetEnt();
      i = 0;
   catch (Exception e)
      throw new FaultException<FaultContract>(new FaultContract(e.ToString()));

Open in new window

Question by:MarcoCastro
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 34966620
Your logic with the i variable in the if statement looks bad to me. By resetting i to 0, it's never reaching 500 (assuming it's not initialised to a value above 500, which you've left out of the code sample), which is an infinite loop, which would be why your memory is spiralling out of control.

You might want to explain what your code is supposed to be doing, as that might make it easier to help you. Without that, I can't really offer you alternatives.

Author Comment

ID: 34969139
Hi, the i variable is not a problem (it is i++, so it is incremented). The reason of i is: load 500 AddObject and then save them in a single process. It is to make the process as fast as possible.

The code is intended to transfer a huge amount of data from one table to another. I can`t do it directly in the database because my LinqQuery if populated by a Dot.Net routine. After populated its content is transfered to a table in the SQL FireBird. So, for each record in LinqQuery one new object is the created as an entity and saved in the database.

Marco Castro

Accepted Solution

MarcoCastro earned 0 total points
ID: 34991704
The answer is: detach all created objects.

Author Closing Comment

ID: 35034603
I got the answer by myself.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question