NightOwl888 commented on issue #784: URL: https://github.com/apache/lucenenet/issues/784#issuecomment-1358694734
`RAMBufferSizeMB` is for *increasing* the amount of allocations to improve performance when indexing a large number documents, as pointed out in [the demo](https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Demo/IndexFiles.cs#L103-L107). `RAMPerThreadHardLimitMB` controls how frequently a background flush will occur. Both of these settings are fully implemented and a flush will cause Lucene.NET to release the references. But at the end of the day, the garbage collector is in charge after the references have been released by Lucene.NET. See [Fundamentals of garbage collection](https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals) While it is generally discouraged to run a garbage collection yourself, .NET does provide a [GC.Collect](https://learn.microsoft.com/en-us/dotnet/api/system.gc.collect?view=net-7.0) method to explicitly force a garbage collection. If you run the garbage collector and the amount of RAM doesn't decrease, then perhaps we have an issue. However, do keep in mind that the debugger in Visual Studio adds a lot of memory overhead that won't be seen in production. > **NOTE**: If this is a .NET Framework app or your app is using the .NET Standard 2.0 target of Lucene.NET, there may be another reason for this. The `ConditionalWeakTable<TKey, TValue>` is missing an enumerator prior to .NET Standard 2.1, which is required in several places by Lucene. We [worked around the issue using weak events](https://github.com/apache/lucenenet/pull/613), but at the end of the day `WeakReference` holds onto references longer than `ConditionalWeakTable<TKey, TValue>`. In these cases, not even calling `GC.Collect` can recover the memory, the only option is to wait for the memory to be released. > > There is another option using [WPF WeakEventManager](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/events/weak-event-patterns?view=netdesktop-6.0) that uses `ConditionalWeakTable<TKey, TValue>` plus some native code to resolve the issue, but since there is no support for this on .NET Standard 2.0, we didn't explore this option any further. But since we are now considering dropping support for .NET Standard 2.0 anyway, perhaps it is worth another look. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org