score:2
The MSDN for Enumerable.Select specifies that it "This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action." Hence, it allocates at least memory for the lambda (x=>x
) and for the reference to the collection it is invoked on. However, this takes memory in the order of the complexity of the query and not in the order of the size of the collection and should therefore be mostly negligible.
Memory is only allocated in the order of the size of the collection when the result of the query is iterated. As Pareek's link shows, this usually happens once per query. In LINQ and Deferred Execution (even though it relates to LINQ to SQL), gives a good statement on this: If a LINQ method returns something different than IEnumerable it has to iterate the collection and may therefore allocate new memory (e.g. ToList(), ToArray()) but doesn't have to (e.g. Count()).
Hence, if you end up having some sort of collection in the end which is no IEnumerable, the query will allocate memory in the order of the size of this resulting collection.
Source: stackoverflow.com
Related Articles
- non executing linq causing memory allocation C#
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- LINQ and memory allocation
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- How/Can I use linq to xml to query huge xml files with reasonable memory consumption?
- How to avoid memory overflow when querying large datasets with Entity Framework and LINQ
- Syntax to execute code block inside Linq query?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Best open source LINQ provider
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- C# compiler (csc.exe) memory overflow compiling nested types and Linq
- LINQ WHERE method alters source collection
- Linq memory question
- Where can I view LINQ source code?
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Left outer join using LINQ -- understanding the code
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Does LINQ new up memory when creating returns
- Avoiding code repetition when using LINQ
- get word frequency (count) as property in Linq Object using Regex
- Best Practice for Linq Where with OR clause?
- how would I write linq query that would display user name instead of userID in a gridview
- Blazor How do I merge a JSON to update MongoDB relation based on input
- C# get every n-th element with WHERE, strange result
- How to get column name form a ListView using Linq(Type cast)
- Multiple fields from LINQ to Text Box
- LINQ to SQL: Group, Count, Sum. I'm so confused
- LINQ expression with generic property
- How to convert a data table data into comma-separated list using lambda expression in C#?
- Sort files based upon variable length of numeric digits in their name C#
- Smallest Sum Algorithm
- Filter data between two dates using LINQ
- How to convert a nested for each loop into Linq when the two lists are of different types
- Inner join with linqJS
- Return Enum Name from Integer in LINQ Database Query
- Why C# linq Distinct method is faster
- Linq to group record by multiple column and select first or default record
- EntityFramework - Load IDs to levels down without loading other columns
- Tricky LINQ and nested collection