You’d have to make the delegate handle a member of ‘this’ instead of a local variable.
You’re capturing a reference to stack data, and when that variable goes out of scope then the reference in your lambda will be invalid.
You may also be able to do a TSharedPtr as a local variable and capture that (by value). Because then the handle won’t go out of scope when the function ends.
No. When the delegate is removed, the lambda will be destructed which will destruct your copy of the shared ptr and the handle it was referencing will be free’d.
Not that come to mind.
That looks like it should be fine. You have to be careful when capturing stuff (like that delegate) by reference but since there’s no way for the Added lambda to be called if the delegate no longer exists you should be fine.