开发者

UserPrincipal.GetGroups leaking

I've tracked down a leak to my group enumeration code. I've written a test routine and I'm trying to dispose of everything but still it leaks.

Does anyone see what I'm doing wrong? In my test, I call it 100 times in a row and on my small domain, the memory footprint goes from 32MB to over 150MB.

    private void EnumGroups()
    {
        try
        {
            using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "domainname.com"))
            {

                using (PrincipalSearcher srch = new PrincipalSearcher())
                {
                    srch.QueryFilter = new UserPrincipal(context);

                    // do the search
                    using (PrincipalSearchResult<Principal> results = srch.FindAll())
                    {
                        // enumerate over results
                        foreach (UserPrincipal up in results)
                        {
         开发者_JAVA百科                   using (PrincipalSearchResult<Principal> groups = up.GetGroups())
                            {
                                foreach (GroupPrincipal gp in groups)
                                    gp.Dispose();
                            }
                            up.Dispose();
                        }
                    }
                }
            }
        }
        catch (Exception exc)
        {
            Trace.WriteLine(exc);
        }
    }


Execute GetMembers from another temp domain:

dTaskTemporaryDomain = AppDomain.CreateDomain("BUHLO_POBEDIT_ZLO");
        var currentAssembly = Assembly.GetExecutingAssembly();
        AdsApiHelper = (AdsApiHelper)_adTaskTemporaryDomain.CreateInstanceAndUnwrap(currentAssembly.GetName().FullName, typeof(AdsApiHelper).ToString());
        var members = AdsApiHelper.GetMembers(GroupName);
 AppDomain.Unload(_adTaskTemporaryDomain)

...
[serializeble]
class AdsApiHelper {
  GetMembers(String GroupName){
   .....
   return groupPrincipal.GetMembers().Select(m=>m.SamAccountName);
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜