문제

We moved our web system to Windows authentication. After deploying it to production environment we faced memory leak. We defined it was paged pool memory leak (tag Toke) using poolmon.exe util. 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.

도움이 되었습니까?

해결책 2

Method UserPrincipal.FindByIdentity() has memory leak.

다른 팁

There is possibly a bug in the implementation of PrincipalContext and/or UserPrincipal causing failure to auto-dispose of an instance. I have seen this previously. You can easily confirm/fix this by replacing the using by a try-finally, as below.

PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName);
try
{
     isValid = pc.ValidateCredentials(login, password);
}
finally
{
     pc.Dispose();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top