1
I’m searching thousands of groups with hundreds of users each of Active Directory, but it’s consuming a lot of memory. It starts with about 300 MB and when it reaches about 1800 MB, seen in the task manager, an Outofmemoryexception is released. The exception is made when this part of the code is being executed.
foreach (string objectGUID in listGroups) { GroupDTO objGroup = new GroupDTO(); objGroup = ADHelper.GetGroupByGUID(objectGUID, domainInfo.GeneratePathOfDomainObj(domainInfo.RootDN), domainInfo.UserName, domainInfo.Password, domainInfo.AuthType, new string[] { "distinguishedname", "name", "objectGUID", "samaccountname", "mail", "description", "whenchanged", "grouptype", "primaryGroupToken" }); List listUsersGroup = new List(); //Uma lista com todos os ID (ObjectGUID) do grupo atual listUsersGroup = ADHelper.GetUsersFromGroup(objectGUID, domainInfo.GeneratePathOfDomainObj(domainInfo.RootDN), domainInfo.UserName, domainInfo.Password, domainInfo.AuthType, new string[] { "objectguid" }, domainInfo.PropertiesGroupsAndUsers, domainInfo.RootDN); Dictionary dicGroup = new Dictionary(); string jSonGroup = JsonConvert.SerializeObject(objGroup); dicGroup.Add("group", jSonGroup); dicGroup.Add("lstUser", listUsersGroup); arrayListGroups.Add(dicGroup); }
You need to see if there are other complicated things besides that and only then it pops. But it can be right there. There is no miracle. Are you using 32bits? The limit is more or less the same. Will need all this together?
– Maniero
Segment your implementation, via logical unit, blocks or pages. Work with subsets, for example group by group. Do not load everything into memory at the same time.
– OnoSendai
This part of the code is from the Importgroups(listGroups) method. I have already tried to divide the listGroups into four more or less equal parts and perform Importgroups(listGroups) for each of these parts. I tried even splitting 10 parts and running, one at a time, the Importgroups(), but always the memory goes up absurdly until reaching some 1800 MB ~ 2000 MB in the Task Manager and give Outofmemoryexception (I am an intern, so forgive me if I’m doing nonsense).
– user86153
It was resolved. The problem was within the Getusersfromgroup() method that instantiated a class that received AD search results without a Dispose() accumulating resources indefinitely in memory. Thanks for the answers :)
– user86153