I noticed that when I create and destroy lots of Actors with internal use of Dynamic Multicast Delegates, I get a memory leak if I don’t manually unbind all of the internal events on destroy.
I declare the delegate like this:
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnAllMotionsReceived);
FOnAllMotionsReceived OnAllMotionsReceived;
And bind it like this:
MotionRegister->OnAllMotionsReceived.AddDynamic(this, &UMotionComponent::ApplyMotions);
As these are all internal, nothing else should hold a reference to them, so I assume there would be nothing left behind.
Clearing the delegate fixes the leak:
MotionRegister->OnAllMotionsReceived.Clear();
If it’s standard practice to unbind internal delegates then no worries.