简体   繁体   English

使用DirectoryServices.AccountManagement时内存泄漏

[英]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.

相关问题 使用DirectoryServices.AccountManagement从OU获取组 - Get Groups From OU using DirectoryServices.AccountManagement DirectoryServices.AccountManagement-组成员身份检查效率 - DirectoryServices.AccountManagement - group membership checking efficiency 单声道和Active Directory:DirectoryServices.AccountManagement异常 - Mono & Active Directory: DirectoryServices.AccountManagement exception 想要在不使用samAccountName或DirectoryServices.AccountManagement的情况下查找广告组的SID。 - Want to look up an AD Group's SID without using samAccountName or DirectoryServices.AccountManagement 使用DirectoryServices.AccountManagement,如何获取活动目录安全组的电子邮件地址? - Using DirectoryServices.AccountManagement, how do I get the e-mail address of an active directory security group? 使用System.DirectoryServices.AccountManagement时的DirectoryServicesCOMException - DirectoryServicesCOMException when working with System.DirectoryServices.AccountManagement 使用System.DirectoryServices.AccountManagement时,Active Directory用户创建延迟 - Delay in Active Directory user creation when using System.DirectoryServices.AccountManagement 在IIS中部署时,使用System.DirectoryServices.AccountManagement的代码引发异常 - Code using System.DirectoryServices.AccountManagement throws exception when deployed in IIS 将 System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials 与 SAM 一起使用时出现奇怪的错误 - Strange Error When Using System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials with SAM 如何使用 System.DirectoryServices.AccountManagement 在多个域中搜索? - How to search in multiple domains using System.DirectoryServices.AccountManagement?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM