none
Is Memory Consumed by LINQ RRS feed

  • Question

  • Hello

    Is LINQ can consume memory ??

    If Yes, How can we release the memory consumed by LINQ ??


    Thanks & Regards,
    Naga Suresh D
    Saturday, May 3, 2014 2:42 PM

Answers

  • Linq is just a set of instructions. It's not an object. Hence it doesn't consume any memory on heap or stack. So, you don't need to worry about cleaning any memory.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, May 5, 2014 7:19 AM

All replies

  • Hello,

    >>Is LINQ can consume memory?

    Yes, it is.

    >>If Yes, How can we release the memory consumed by LINQ?

    Objects in memory filled by LINQ will not be disposed until GC. If we want to dispose them, we need to dispose them manually as below:

    IQueryable<Order> result = (from OA in db.Orders
    
                                                where OA.OrderName == db.Orders.Where(order => order.OrderID == 1).FirstOrDefault().OrderName
    
                                                select OA); 
    
                    foreach (Order order in result)
    
                    {
    
                        order.Dispose();
    
                    }
    
    And for achieving this, we need to let entity implement the IDisposable interface: IDisposable and implement the interface as:

    http://msdn.microsoft.com/en-us/library/system.idisposable.aspx

    If I misunderstand, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 5, 2014 2:26 AM
    Moderator
  • Linq is just a set of instructions. It's not an object. Hence it doesn't consume any memory on heap or stack. So, you don't need to worry about cleaning any memory.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, May 5, 2014 7:19 AM