Search code examples
c#rider

Meaning of "Object allocation: LINQ method call"


I use JetBrains Rider for programming in C#. Often, Rider underscores some operations in my code like the following one list.Where LINQ method call:

enter image description here

When I put my mouse cursor over theWhere keyword, it shows the following message:

enter image description here

The compilation doesn't generate any warnings nor the Rider itself shows any warnings. But then what is the meaning of it ?


Solution

  • The highlight comes from a plugin, "Heap Allocations Viewer".

    The highlight is there to inform you of code that does allocations, boxing, unboxing, etc.

    These things may mean something to you, but usually only if you're dealing with a very constrained execution environment or constrained execution profiles, such as low-memory embedded systems or games programming, where memory allocations or garbage collections are something you want to avoid if you can.

    If you don't really care about what this plugin is telling you, you can safely disable or remove it from Rider by going to File->Settings->Plugins and searching for it.

    The reason that the compiler neither warns nor produces an error about this is that the code is in fact completely benign and unproblematic, but it has some sideeffects that you may want to avoid in lieu of the situations described above.