If I understood correctly, you want the View
to be destroyed after deactivating it from the region. Although the
property is needed to free and destroy the Object instance, it also needs the View to don’t have any other strong reference to it.
Basically, when a view / view model that implements the IRegionMemberLifetime
interface is deactivated in a
will check its
property. If this property returns false, the behavior will automatically remove the view / view model from the
, and as the Region
will no longer hold a reference to the view / view model, it will be marked to be garbage collected unless another object of your application is holding a strong reference to it.
Take into account that even if an object is marked to be garbage collected, it will remain in memory until the
decides to run. What this means is that even if the views / view models are being properly marked to be garbage collected, they would be alive until the garbage collector passes through. You could invoke, however, the
method after deactivating the view / view model in order to detect whether the instances are erased or not (remember that the
method should only be used with testing purposes as its usage is not recommended in a common application).
If your instances are kept alive even after running the GC
, it would be useful if you could provide us more information about any reference to the view / view model so we could go through the cause that is keeping them alive in the application.
I hope this helps.