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
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’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.