Web 应用程序代码中可能会发生内存泄漏

Microsoft.Windows.InternetInformationServices.10.0.ApplicationPool.MemoryLeak.Monitor (UnitMonitor)

此监视器在应用程序池因超出内存配置阀值而被回收时查看记录的事件,并在应用程序池回收过于频繁时将其状态更改为警告(基于监视器的配置)。这是手动重置监视器,表示它不会自动切换到正常状态。要将监视器切换到正常状态,需要使用运行状况资源管理器重置监视器。

Knowledge Base article:

摘要

应用程序池回收太频繁,因为其虚拟或物理内存占用已达到配置限制。这可能表明应用程序池正在执行的代码中发生内存泄露。

配置

此监视器的工作方式为查找大量由于达到配置的内存使用率阈值(在 IIS 管理工具中配置此值)导致的应用程序池回收事件。可为此监视器配置两个参数。第一个参数为“发生次数”,即此监视器正在查找的事件需要在配置的时间间隔内发生的次数。第二个参数为“分钟数”,即此监视器查找事件发生的时间间隔。

原因

解决方法

若要通过使用 IIS 管理器检查或配置应用程序池限制设置,请执行以下操作:

注意:由于这是一个手动重置监视器,因此在修复此问题之后,需在运行状况资源管理器中重置此监视器的状态。通过右键单击此监视器并选择“重置运行状况”菜单项,可完成此操作。如果没有手动重置此监视器,它将不会切换到正常状态。

Element properties:

TargetMicrosoft.Windows.InternetInformationServices.10.0.ApplicationPool
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.Windows.InternetInformationServices.10.0.RepeatedEventLogManualReset2StateMonitorType
RemotableTrue
AccessibilityPublic
Alert Message
Web 应用程序代码中可能会发生内存泄漏
由于超出在服务器 {1} 中为应用程序池 {0} 指定的内存阀值,此应用程序池已被多次重新启动。这可能表示在 Web 应用程序代码中存在内存泄漏。
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.Windows.InternetInformationServices.10.0.ApplicationPool.MemoryLeak.Monitor" Accessibility="Public" Enabled="true" Target="Microsoft.Windows.InternetInformationServices.10.0.ApplicationPool" ParentMonitorID="SystemHealth!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="Microsoft.Windows.InternetInformationServices.10.0.RepeatedEventLogManualReset2StateMonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Microsoft.Windows.InternetInformationServices.10.0.ApplicationPool.MemoryLeak.Monitor_AlertMessageResourceID">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Warning</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="IISCommon!Microsoft.Windows.InternetInformationServices.ApplicationPool"]/PoolID$</AlertParameter1>
<AlertParameter2>$Target/Host/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</AlertParameter2>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="PotentialMemoryLeakDetected" MonitorTypeStateID="RepeatedEventRaised" HealthState="Warning"/>
<OperationalState ID="Healthy" MonitorTypeStateID="ManualResetEventRaised" HealthState="Success"/>
</OperationalStates>
<Configuration>
<RepeatedComputerName>$Target/Host/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</RepeatedComputerName>
<RepeatedLogName>System</RepeatedLogName>
<RepeatedExpression>
<And>
<Expression>
<RegExExpression>
<ValueExpression>
<XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>
</ValueExpression>
<Operator>MatchesRegularExpression</Operator>
<Pattern>^(5117|5077)$</Pattern>
</RegExExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">PublisherName</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Microsoft-Windows-WAS</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Params/Param[2]</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Target/Property[Type="IISCommon!Microsoft.Windows.InternetInformationServices.ApplicationPool"]/PoolID$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</RepeatedExpression>
<NumberOfSeconds>3600</NumberOfSeconds>
<NumberOfOccurrences>10</NumberOfOccurrences>
</Configuration>
</UnitMonitor>