[英]Memory leaks when using DirectoryServices.AccountManagement
We moved our web system to Windows authentication. 我们将Web系统移至Windows身份验证。 After deploying it to production environment we faced memory leak. 将其部署到生产环境后,我们面临着内存泄漏。 We defined it was paged pool memory leak (tag Toke) using poolmon.exe util. 我们使用poolmon.exe util将其定义为页面缓冲的池内存泄漏(标记Toke)。 During recent modification we only added 2 following methods: 在最近的修改中,我们仅添加了以下两种方法:
using System.DirectoryServices.AccountManagement;
private bool IsLoginValid(string login, string password)
{
bool isValid = false;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName))
{
isValid = pc.ValidateCredentials(login, password);
}
return isValid;
}
private bool isMemberOf(string login, string group)
{
bool result = false;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName))
{
using (UserPrincipal user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, login))
{
if (user != null)
{
result = user.IsMemberOf(pc, IdentityType.Name, group);
}
}
}
return result;
}
Please, help to identify the exact point of leaking and if possible provide with a workaround. 请帮助确定泄漏的确切点,并在可能的情况下提供解决方法。 Thank you. 谢谢。
There is possibly a bug in the implementation of PrincipalContext
and/or UserPrincipal
causing failure to auto-dispose of an instance. PrincipalContext
和/或UserPrincipal
的实现中可能存在错误,导致无法自动处理实例。 I have seen this previously . 我以前看过这个 。 You can easily confirm/fix this by replacing the using
by a try-finally
, as below. 您可以轻松地确认/由替换解决这个问题using
一个try-finally
,如下图所示。
PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName);
try
{
isValid = pc.ValidateCredentials(login, password);
}
finally
{
pc.Dispose();
}
方法UserPrincipal.FindByIdentity()
有内存泄漏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.