Particular / NServiceBus

Build, version, and monitor better microservices with the most powerful service platform for .NET
https://particular.net/nservicebus/
Other
2.07k stars 650 forks source link

Creating an endpoint and not referencing the instance results in memory/resource leak #7066

Open ramonsmits opened 1 month ago

ramonsmits commented 1 month ago

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

  1. Start an instance in separate method returning nothing, ensure its not inlined
  2. Create an infinite loop that triggers the GC to collect and wait for finalizers with a sleep/delay
  3. Observe that the instance remains running

Relevant log output

No response

Additional Information

No response

ramonsmits commented 1 month ago

This happens for example currently indirectly in ServiceControl indirectly at: