botbuilder-dotnet: LanguageGeneratorExtensions.UseLanguageGeneration GC root / memory leak

Background

There is an issue when using LanguageGeneratorExtensions.UseLanguageGeneration at scale since it uses a static dictionary to store lg managers.

See https://github.com/microsoft/botbuilder-dotnet/blob/f55bbc3f19ca874dceebb59c3ffcb31688f141b4/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/LanguageGeneratorExtensions.cs#L63

and

https://github.com/microsoft/botbuilder-dotnet/blob/f55bbc3f19ca874dceebb59c3ffcb31688f141b4/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/LanguageGeneratorExtensions.cs#L17

This is a GC root so this and any objects in it are never released from memory and over time in a multi tenanted environment this eventually leads to out of memory issues.

We have worked around it by providing our own copy of the behaviour which does not cache. Would it be possible to add an additional parameter to indicate whether or not to cache the lg managers?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Apologies for the delay - have tested my use case with solution 1 and it seems to be better. Will update the issue with some supporting data this week

@Danieladu not yet - will update today or tomorrow

Will do and report back asap

@jamesemann Feel free to test the PR. Thanks. I have two solutions in this PR. The first solution uses ConditionalWeakTable. The second solution uses “MemoryCache” which is Commented out. You can remove the // marks and make some testing. Thanks! I have no idea which solution is better.