Started using Action<> blocks in my code and now I get GC.Collect() spikes, what am I doing wrong?

I’m really just using these code blocks out of convenience and ?cleaner code?. Anyone know why using actions like this gets GC.Collect spikes? Once I got how to use actions I just started using them all over the show so wishing I can understand how I can get around this

public void DoStuff(){
            Action<int, int> code = (i, ii) => {
                localVariables*.something = something;*

localVariables*.bingBong = bingBongs[ii];*
ForActions(code, localVariables.Length, 0);
public static void ForActions(Action<int, int> code, int length, int ii) {
* for(int i = 0; i < length; i++){*
code(i, ii);


Using Action is not like using function pointer in C/C++. They look like they do the same but while function pointer are just reference to a method and then are just 32 or 64 bits, an Action is a actually a generic version of the old delegate:

   delegate void Action(int a, int b);
   Action action;

would be the same as:

 Action<int, int> action; 

But in this case a class is actually created since delegate is itself a class.

Here is what Action looks like:,9147ae6f76643aae

and here is delegate, pay special attention to InvokeXXXX methods:,0dd8585ba1833ad7

and calling the action class for Invoke which in turns uses all kind of submethods within.

This is probably why you see those spikes that I would not really bother about though.