From de5930e0d2ce2559719d78d84804c5f3aed36336 Mon Sep 17 00:00:00 2001 From: FabioDefilippo Date: Sat, 16 May 2026 12:51:21 +0200 Subject: [PATCH 1/4] Update BaseContext.cs garbage collection implemented --- src/BaseContext.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/BaseContext.cs b/src/BaseContext.cs index a8db491..abfdf27 100644 --- a/src/BaseContext.cs +++ b/src/BaseContext.cs @@ -161,6 +161,32 @@ private void Dispose(bool disposing) // TODO: free unmanaged resources (unmanaged objects) and override finalizer // TODO: set large fields to null + Timer = null; + CancellationTokenSource = null; + ResolvedCollectionMethods = null; + Logger = null; + LoopEnd = null; + LDAPUtils = null; + LoopDuration = null; + LoopInterval = null; + CurrentLoopTime = String.Empty; + CollectionTask = null; + StatusInterval = 0; + Threads = 0; + Throttle = 0; + Jitter = 0; + PortScanTimeout = 0; + LdapFilter = String.Empty; + SearchBase = String.Empty; + DomainName = String.Empty; + CacheFileName = String.Empty; + ComputerFile = String.Empty; + ZipFilename = String.Empty; + ZipPassword = String.Empty; + CurrentUserName = String.Empty; + RealDNSName = String.Empty; + OutputPrefix = String.Empty; + OutputDirectory = String.Empty; disposedValue = true; } } From 8eb1523b6f222bc9268eb5ce53a622d5694598b0 Mon Sep 17 00:00:00 2001 From: FabioDefilippo Date: Sat, 16 May 2026 13:02:05 +0200 Subject: [PATCH 2/4] Free memory disposing Time and CancellationTokenSource Implemented - Timer?.Dispose(); - CancellationTokenSource?.Dispose(); --- src/BaseContext.cs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/BaseContext.cs b/src/BaseContext.cs index abfdf27..e105a84 100644 --- a/src/BaseContext.cs +++ b/src/BaseContext.cs @@ -157,37 +157,12 @@ private void Dispose(bool disposing) if (disposing) { // TODO: dispose managed state (managed objects) + Timer?.Dispose(); + CancellationTokenSource?.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override finalizer // TODO: set large fields to null - Timer = null; - CancellationTokenSource = null; - ResolvedCollectionMethods = null; - Logger = null; - LoopEnd = null; - LDAPUtils = null; - LoopDuration = null; - LoopInterval = null; - CurrentLoopTime = String.Empty; - CollectionTask = null; - StatusInterval = 0; - Threads = 0; - Throttle = 0; - Jitter = 0; - PortScanTimeout = 0; - LdapFilter = String.Empty; - SearchBase = String.Empty; - DomainName = String.Empty; - CacheFileName = String.Empty; - ComputerFile = String.Empty; - ZipFilename = String.Empty; - ZipPassword = String.Empty; - CurrentUserName = String.Empty; - RealDNSName = String.Empty; - OutputPrefix = String.Empty; - OutputDirectory = String.Empty; - disposedValue = true; } } } From 79d80aca727cf54f92c2c55efdbeba2c69f77164 Mon Sep 17 00:00:00 2001 From: FabioDefilippo Date: Sat, 16 May 2026 13:04:03 +0200 Subject: [PATCH 3/4] Update BaseContext.cs --- src/BaseContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BaseContext.cs b/src/BaseContext.cs index e105a84..ae364ae 100644 --- a/src/BaseContext.cs +++ b/src/BaseContext.cs @@ -163,6 +163,7 @@ private void Dispose(bool disposing) // TODO: free unmanaged resources (unmanaged objects) and override finalizer // TODO: set large fields to null + disposedValue = true; } } } From 4623969695231e947cc775b0e04f12ca22cfafb3 Mon Sep 17 00:00:00 2001 From: FabioDefilippo Date: Sat, 16 May 2026 14:18:05 +0200 Subject: [PATCH 4/4] delete "lower" var and added StringComparison.OrdinalIgnoreCase More efficient and less memory, no duplicates --- src/Producers/LdapProducer.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Producers/LdapProducer.cs b/src/Producers/LdapProducer.cs index c5c602a..cb501b3 100644 --- a/src/Producers/LdapProducer.cs +++ b/src/Producers/LdapProducer.cs @@ -147,10 +147,9 @@ public override async Task Produce() if (searchResult.TryGetDistinguishedName(out var distinguishedName)) { - var lower = distinguishedName.ToLower(); - if (lower.Contains("cn=domainupdates,cn=system")) + if (distinguishedName.Contains("cn=domainupdates,cn=system", StringComparison.OrdinalIgnoreCase)) continue; - if (lower.Contains("cn=policies,cn=system") && (lower.StartsWith("cn=user") || lower.StartsWith("cn=machine"))) + if (distinguishedName.Contains("cn=policies,cn=system", StringComparison.OrdinalIgnoreCase) && (distinguishedName.StartsWith("cn=user", StringComparison.OrdinalIgnoreCase) || distinguishedName.StartsWith("cn=machine", StringComparison.OrdinalIgnoreCase))) continue; await Channel.Writer.WriteAsync(searchResult, cancellationToken); @@ -242,4 +241,4 @@ public override async Task ProduceConfigNC() } } } -} \ No newline at end of file +}