Search code examples
c#delegatesanonymous-methods

Do anonymous methods consume memory?


Do Anonymous Methods, Delegates, Action, Func and alike, allocate/consume/eat memory on your computer?

If so, do they allocate same memory on each variable on captured code block?


Solution

  • Of course they do, just like any other normal function. How can they be executed at run time if they wouldn't be "stored" somewhere in memory?

    But if you are asking if they consume more memory on every call (as in allocating dynamic memory), then no, they don't do that on their own.