-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DiagnosticsCollector provokes memory leaks #645
Comments
In above test case, you have not Dispose the resolver ( var resolver = builder.Build();), so all instances may be retained, not just DiagnosticsCollector. If you call GC.Collect(), is there any guarantee that all finalisers will be executed in the line immediately following it? The only way to be sure is to Dispose. |
It is not that DiagnosticsCollector, it's that the DiagnosticsCollector is preventing the gc to collect instances that are not referenced anymore, but probably the diagnostics is keeping some reference to them. Maybe it wasn't clear in the test. but it is resolved using a factory Then, this object is unreferenced everywhere, because other new object has been created So, if it is unreferenced everywhere, if you call the gc, this object should be collected and cleaned at some point. You can see exactly that behaviour in the test MemoryLeakGroundTruth, that have this logic but not using VContainer. My point is that the gc is not able to clean this unreferenced object because the diagnosticsCollector is keeping track of it, although is not been using anymore. And you can see that this is true because the same test, with diagnosticsCollector = null, the object is correctly collected. This was only a toy example to show this issue, but I had it in a real logic, where a type was resolved using a reference in a factory. It had a problem because I was overwritting the object that need to be used in the resolve, and the old instances weren't never collected by the GC. But this happened only with the Diagnistic On. If I wasn't using the diagnostic, the gc collector worked as expected. |
I was having a strange behavior with some instances not destroyed and some memory leaks.
Then I realized that this behavior was only occurring when VContainerSettings.DiagnosticsEnabled = true.
I have done a Test trying to isolate and simplify my case and indeed, aparrently the Diagnostics is creating some memory leak, not allowing the gc to destroy some instances
The text was updated successfully, but these errors were encountered: