title: High memory allocations when unregistering delegates from event in C#
body: <p>We are developing a game with the <a href="http://www.unity3d.com" rel="nofollow noreferrer">Unity3D</a> engine (which uses Mono for user code - our code is written in C#).</p>
  
  <p>The scenario is that we have a class exposing an event, with around ~ 250 registrations to that event (each level object on the game's map registers itself to that event):</p>
  
  <pre><code>// Every level registers itself (around 250 levels)
  ScoresDataHelper.OnScoresUpdate += HandleOnScoresUpdate;
  </code></pre>
  
  <p>When destroying this scene, every object unregisters itself from the event:</p>
  
  <pre><code>ScoresDataHelper.OnScoresUpdate -= HandleOnScoresUpdate;
  </code></pre>
  
  <p>When using the built-in profiler, i am seeing a huge memory allocation, digging deeper shows that it is due to the delegates being unregistered.</p>
  
  <p>I suspect this is due to the fact that Delegates are immutable and when chaining them together, new instances are created ?</p>
  
  <p>Here's a screenshot from Unity's profiler:</p>
  
  <p><img src="https://i.stack.imgur.com/ABUrg.png" alt="Profiler"></p>
  
  <p>Is there any way to avoid these memory allocations when dealing with a large number of event subscriptions?</p>