Possible Memory Leak or Issue With Unity Event Implementation/Usage


I’m facing this issue for the following use case of using Unity Event :

  1. Have a reference of Unity Event Object.
  2. Add any number of listeners to it.
  3. Invoke the event once.
  4. Now Remove each event listener one by one.

Now in above scenario , until I release the instance of the event listener , the listener basically holds a reference to the target of each listener, even though I have removed the listeners. I could trace this to how the copy of listener targets are maintained inside ‘m_executingCalls’ list internally.

Now is there something wrong by the way I’m trying to use Unity Events or is there something else I’m missing. Seems like a fairly usual way in which someone would use the API.

Thanks For Reading.

I also ran into this issue in Unity 2020.3.25. I am using reflection after calling RemoveAllListeners to get and clear ‘m_ExecutingCalls’ list without calling persistent calls.