Memory leaks 获得分配的TimerQueueTimer对象太多,占用了大量内存

Memory leaks 获得分配的TimerQueueTimer对象太多,占用了大量内存,memory-leaks,timer,Memory Leaks,Timer,我有一个运行的Web API,它与服务总线连接,将消息写入主题并部署在服务结构中。我看到异常高的内存使用率,大部分内存被TimerQueueTimer对象占用,尽管我没有显式初始化任何计时器 当我回溯这些计时器是如何创建的时,我会看到以下名称空间: Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryModules.<Modules>k__BackingField -> Microsoft.A

我有一个运行的Web API,它与服务总线连接,将消息写入主题并部署在服务结构中。我看到异常高的内存使用率,大部分内存被TimerQueueTimer对象占用,尽管我没有显式初始化任何计时器

当我回溯这些计时器是如何创建的时,我会看到以下名称空间:

Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryModules.<Modules>k__BackingField ->
Microsoft.ApplicationInsights.Extensibility.Implementation.SnapshottingList<Microsoft.ApplicationInsights.Extensibility.ITelemetryModule>.Collection ->
System.Collections.Generic.List<Microsoft.ApplicationInsights.Extensibility.ITelemetryModule>._items ->
Microsoft.ApplicationInsights.Extensibility.ITelemetryModule[16] at [4] ->
Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule.timer ->
Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.Implementation.Timer.Timer.timer ->
System.Threading.Timer.m_timer

--------------------------------------------

Microsoft.Azure.ServiceBus.TopicClient.<ServiceBusConnection>k__BackingField ->
Microsoft.Azure.ServiceBus.ServiceBusConnection.<ConnectionManager>k__BackingField ->
Microsoft.Azure.Amqp.FaultTolerantAmqpObject<Microsoft.Azure.Amqp.AmqpConnection>.taskCompletionSource ->
System.Threading.Tasks.TaskCompletionSource<Microsoft.Azure.Amqp.AmqpConnection>.m_task ->
System.Threading.Tasks.Task<Microsoft.Azure.Amqp.AmqpConnection>.m_result ->
Microsoft.Azure.Amqp.AmqpConnection.heartBeat ->
Microsoft.Azure.Amqp.AmqpConnection+HeartBeat+TimedHeartBeat.heartBeatTimer ->
System.Threading.Timer.m_timer ->
System.Threading.TimerHolder.m_timer ->
System.Threading.TimerQueueTimer.m_next ->

--------------------------------------------

Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientCache<ServiceClient.HttpCommunicationClient>.cacheCleanupTimer ->
System.Threading.Timer.m_timer ->
System.Threading.TimerHolder.m_timer   
Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryModules.k\uu BackingField->
Microsoft.ApplicationInsights.Extensibility.Implementation.SnapshottingList.Collection->
System.Collections.Generic.List.\u项->
Microsoft.ApplicationInsights.Extensibility.ITelemetryModule[16]位于[4]->
Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule.timer->
Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.Implementation.Timer.Timer.Timer->
System.Threading.Timer.m_Timer
--------------------------------------------
Microsoft.Azure.ServiceBus.TopicClient.k__BackingField->
Microsoft.Azure.ServiceBus.ServiceBusConnection.k__BackingField->
Microsoft.Azure.Amqp.FaultTolerantAmqpObject.taskCompletionSource->
System.Threading.Tasks.TaskCompletionSource.m_任务->
System.Threading.Tasks.Task.m_结果->
Microsoft.Azure.Amqp.AmqpConnection.heartBeat->
Microsoft.Azure.Amqp.AmqpConnection+HeartBeat+TimedHeartBeat.heartBeatTimer->
System.Threading.Timer.m_Timer->
System.Threading.TimerHolder.m_timer->
System.Threading.TimerQueueTimer.m_next->
--------------------------------------------
Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientCache.CacheCleanupTime->
System.Threading.Timer.m_Timer->
System.Threading.TimerHolder.m_定时器

不确定为什么这些计时器从未被收集,而且所有这些都存在于Gen2中。在一段时间内,内存会出现峰值,应用程序会变得无响应。当这些计时器对象从未被收集时,有什么线索吗

我们最近看到了一个类似的问题,主要是关于
TimerQueueTimer
和应用程序洞察


我们将Microsoft.ApplicationInsights.AspNetCore从2.3.0升级到了2.8.2,这似乎解决了这个问题。很可能是,在v2.4.0中修复了。

出于好奇,您使用了什么工具来获取报告?我使用了JetBrains DotMemory,我遇到了完全相同的问题(使用相同的工具进行调查)。你找到什么导致问题的线索了吗?还没有。。不同的工具表现出不同的特点。我试过ANTS内存分析器,它显示计时器对象的大小只有9MB。甚至WinDBG也显示9MB大小。因此,计时器在我的情况下不是一个问题。使用WinDBG的“dumpheap-stat”命令检查最大的消耗对象。我们还发现代码中重复加载了太多的动态模块。怀疑这可能是问题所在。还在分析。@vrcks,你有没有对此有过更新?我也面临同样的问题。谢谢