Web 應用程式程式碼可能發生記憶體流失

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

此監視器會在因超出所設定記憶體閾值而回收應用程式集區時查閱所記錄的事件,並在過於頻繁回收應用程式集區時將其狀態變更為警告 (根據監視器的組態)。這是手動重設監視器,這表示它不會自動切換至狀況良好狀態。若要將監視器切換至狀況良好狀態,您必須使用健全狀況總管來重設監視器。

Knowledge Base article:

摘要

應用程式集區的回收次數過於頻繁,因為其虛擬或實體記憶體耗用量已達所設定的限制。這可能表示應用程式集區正在執行的程式碼中有記憶體流失的情況。

設定

此監視器的運作方式是尋找因已達所設定記憶體使用量閾值 (此值是在 IIS 系統管理工具中設定) 而發生的一系列應用程式集區回收事件。您可以針對此監視器設定兩個參數。第一個參數是「發生次數」,也就是監視器正在尋找的必須在所設定時間間隔內發生的事件次數。第二個參數是「分鐘數」,也就是監視器尋找所發生事件的時間間隔。

原因

解決方式

使用 [IIS 管理員] 檢查或設定應用程式集區限制設定:

請注意: 因為這是手動重設監視器,所以在修正此問題後,您將必須在健全狀況總管中重設此監視器的狀態。您可以對監視器按一下滑鼠右鍵並選取 [重設健全狀況] 功能表項目來執行此操作。除非您手動重設監視器,否則它不會切換至狀況良好狀態。

Element properties:

TargetMicrosoft.Windows.InternetInformationServices.6.2.ApplicationPool
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.Windows.InternetInformationServices.6.2.RepeatedEventLogManualReset2StateMonitorType
RemotableTrue
AccessibilityPublic
Alert Message
Web 應用程式程式碼可能發生記憶體流失
伺服器 {1} 上的應用程式集區 {0} 因超出針對此應用程式集區所指定的記憶體閾值而已重新啟動多次。這可能表示 Web 應用程式的程式碼中有出現記憶體流失。
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.Windows.InternetInformationServices.6.2.ApplicationPool.MemoryLeak.Monitor" Accessibility="Public" Enabled="true" Target="Microsoft.Windows.InternetInformationServices.6.2.ApplicationPool" ParentMonitorID="SystemHealth!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="Microsoft.Windows.InternetInformationServices.6.2.RepeatedEventLogManualReset2StateMonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Microsoft.Windows.InternetInformationServices.6.2.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>