How to ensure proper cleanup when scene is unloaded?

27 views
Skip to first unread message

Andy Riedel

unread,
Sep 23, 2019, 6:17:23 PM9/23/19
to StrangeIoC
We use additive scene loading/unloading in our Strange based application. While this works well for initializing our MVCSContext but we are having issues cleaning up during scene unloading. The problems seem to stem from the removal of Command bindings

We are experiencing two problems: 

1) Mediators may not be able to execute Signal -> Commands in their OnRemove method

If ContextView OnDestroy is called prior to other View OnDestroy calls, the MVCSContext's OnRemove causes all Command bindings to be removed:

/// Clean up. Called by a ContextView in its OnDestroy method
public override void OnRemove()
{
base.OnRemove();
commandBinder.OnRemove();
}

 Any subsequent Views/Mediators that are destroyed after this will not be able to execute Commands in the Mediator OnRemove method.

2) Commands used to unload scenes may not be able to execute other Signal -> Commands in their Promise callbacks.

We use Promises to allow asynchronous unloading of our additive scenes. In the completion callback after successfully unloading a scene, the Commands in the context have been removed as well.

Any thoughts or design patterns on how to solve the items above?

Thank you,

Andy 

Will Corwin

unread,
Sep 23, 2019, 7:25:38 PM9/23/19
to Andy Riedel, StrangeIoC
How are you structuring your contexts? Are they siblings or parent/children, or both?

Cross Context bindings shouldn't be affected, so I haven't seen any issue cleaning up multiple contexts on scene changes. That having been said, I don't quite understand your exact use case, so I'd need to know a little more to give a better answer. The nature of Promises does suggest that their callbacks may be referencing things which have already been cleaned up.

I think trying to have a Context clean itself up asynchronously as it destroys itself is a fairly brittle idea, but doable. You may want to manage it in an easier to understand (and outside) way. Otherwise you may find yourself constantly fighting a fragile order of cleanup operations. In general, I work at cleaning up all events, promises, signals and bindings and then nuke entire hierarchies. How you accomplish that is kind of up to you. 

All in all this is a small part of a larger discussion, so some more info may prove valuable! Cheers!

--
You received this message because you are subscribed to the Google Groups "StrangeIoC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to strangeioc+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/strangeioc/95450eca-2cbc-4289-857a-661193d44a2e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages