Is it necessary to unbind events before destroying an actor

I have some custom events bound in an AIController, and I was wondering if it is necessary to unbind those events before calling DestroyActor in order for it to be garbage collected. If it is not necessary, do the events unbind immediately, or only when the controller is garbage collected?

Editing for clarification:

  • Do event bindings prevent garbage collection
  • If not, do they get removed when the actor is flagged for collection, or upon being collected

Yes it is recommended to unbind events when you no longer need them, they can be fired unpredictably and cause bugs very hard to track down.

No they won’t, the references are weak.
The problem is that you don’t know if an object is removed yet and you can call accidentally it.

Best practice, sure. But that doesn’t really address my question. I have run into some other issue regarding destroying the AIController, and I’m doing things a different way now, but it would still be useful to know if event bindings prevent garbage collection (i.e., is unbinding necessary) and, if not, if they get removed when it gets flagged for collection, or upon being collected.

I would also like clarification for this as the question has not really been resolved.

Specifically:

  • Do event bindings prevent garbage collection when an actor gets destroyed

I’m not an expert on this, so maybe someone can correct me if I’m wrong. My understanding is if you have an AActor (or, generally, a UObject) that a delegate is bound to, it can still be garbage collected. I came to this conclusion after reading this doc. Specifically, where it says

the delegate system can keep a weak reference to the object, so that if the object gets destroyed out from underneath the delegate…

This leads me to believe that the object can be garbage collected while the binding remains. This doesn’t necessarily mean it’s a good thing to leave broken bindings hanging like that.