jab icon indicating copy to clipboard operation
jab copied to clipboard

Memory leak issue caused by IDisposable (?)

Open yunusefendi52 opened this issue 1 year ago • 0 comments

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:

var p = new MyServiceProvider();
WeakReference w = new(null);
var i = new Action(() =>
{
    var service = 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

yunusefendi52 avatar Oct 01 '22 03:10 yunusefendi52