后台任务中的 App Insights 内存泄漏

时间:2021-07-09 03:58:12

标签: asp.net-web-api memory-leaks out-of-memory background-process appinsights

我在 .NET web api(.net 4.8 框架)中使用 Simple Injector DI,并且在遥测客户端周围有一个包装类(我自己的实现)。

public class MyAppInsights : IMyAppInsights
{
private static TelemetryClient telemetry;
public MyAppInsights ()
{
if (telemetry == null)
{
telemetry = new TelemetryClient();
}
}
//other interface method implementations
}

简单的注入器启动配置如下

container.Register(Lifestyle.Singleton);

我注意到许多 Httpwebrequest 对象(应用程序洞察)被添加到内存中,而不是为长时间运行的后台任务释放。这个问题是最近在执行导致内存不足异常的长时间运行的后台任务后才出现的。

任何关于如何减少/堵塞内存泄漏/消耗的指针将不胜感激

1 个答案:

答案 0 :(得分:0)

您可以尝试删除 Lifestyle.Singleton 以查看是否仍有内存泄漏。 例如,还可以查看网站。

https://docs.simpleinjector.org/en/latest/quickstart.html

相关问题