11

I was going through different LifetimeManagers available in Unity and was wondering when will we use ExternallyControlledLifetimeManager? Can somebody give me an real life example? The MSDN doc says "A LifetimeManager that holds a weak reference to it's managed instance"..

How can the developer manage the instance and when should he go for such a lifetime manager? Your thoughts on how and when you used it would be great for me and others to understand. Thanks!

1 Answer 1

13

It could be useful if you're going to register an object created by other frameworks or library and you haven't the control of its life, for example a singleton provided by a third-party library.

Because the container keeps only a weak reference, the GC will delete that singleton if there aren't any strong reference. IMO, you should use it only if you can't manage the life time of the instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.