You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to understand the generated code and found out that there is List<object>? _disposables; which keeps the IDisposable object from the service, but I think that also causes the object to leak(?), here is the test to check if the object is leaking:
varp=newMyServiceProvider();WeakReferencew=new(null);vari=newAction(()=>{varservice=p.GetService<IService>();w.Target=service;});i();GC.Collect();Console.WriteLine($"Is the object still alive? {w.IsAlive}");
If the service doesn't implement IDisposable the object didn't leak, but if it does it leak
My use case is that the provider is alive as long as the app still running, I am using dotnet android
The text was updated successfully, but these errors were encountered:
This is possible when the service is registered as transient but also implements IDisposable interface. Because it's transient, a new instance is created every time is requested. The container is supposed to track the lifetime of all services it creates, so it stores the service in the _disposables list. But the _disposables are only disposed when you call .Dispose() on the container itself, meaning that their lifetime is extended to the lifetime of the container.
This problem doesn't happen if you resolve disposable transients from a scope that's returned by CreateScope as it can be disposed earlier than the entire container is.
I am trying to understand the generated code and found out that there is
List<object>? _disposables;
which keeps theIDisposable
object from the service, but I think that also causes the object to leak(?), here is the test to check if the object is leaking:If the service doesn't implement IDisposable the object didn't leak, but if it does it leak
My use case is that the provider is alive as long as the app still running, I am using dotnet android
The text was updated successfully, but these errors were encountered: