Creating an endpoint and not referencing the instance results in memory/resource leak
Describe the bug
Description
Creating an endpoint and not referencing the instance results in memory leak.
Expected behavior
The instance to eventually be able to be garbage collected when there is no longer a reference to the instance.
Actual behavior
When an instance is started but no longer referenced it remains active and in memory for the duration of the application.
Versions
9.0.x
Please list the version of the relevant packages or applications in which the bug exists.
Steps to reproduce
- Start an instance in separate method returning nothing, ensure its not inlined
- Create an infinite loop that triggers the GC to collect and wait for finalizers with a sleep/delay
- Observe that the instance remains running
Relevant log output
No response
Additional Information
No response
This happens for example currently indirectly in ServiceControl indirectly at:
-
https://github.com/Particular/ServiceControl/blob/5.2.4/src/ServiceControl.Audit/Auditing/AuditIngestion.cs
-
https://github.com/Particular/ServiceControl/blob/5.2.4/src/ServiceControl/Operations/ErrorIngestion.cs#L145-L151