Permalink
Browse files

Calling RegisterDecorator on short-lived containers caused memory-lea…

…k due to use of ThreadLocal<T>. Fixes #539
  • Loading branch information...
dotnetjunkie committed Apr 26, 2018
1 parent ce22df6 commit 4b9db7323795b0dc9c5fa2f989eb27e793235bf7
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/SimpleInjector/Decorators/DecoratorExpressionInterceptor.cs
@@ -38,8 +38,15 @@ namespace SimpleInjector.Decorators
internal abstract class DecoratorExpressionInterceptor
{
private static readonly Func<Container, object, ThreadLocal<Dictionary<InstanceProducer, ServiceTypeDecoratorInfo>>> ThreadLocalDictionaryFactory =
(container, key) => new ThreadLocal<Dictionary<InstanceProducer, ServiceTypeDecoratorInfo>>(
() => new Dictionary<InstanceProducer, ServiceTypeDecoratorInfo>());
(container, key) =>
{
var threadLocal = new ThreadLocal<Dictionary<InstanceProducer, ServiceTypeDecoratorInfo>>(
() => new Dictionary<InstanceProducer, ServiceTypeDecoratorInfo>());
container.RegisterForDisposal(threadLocal);
return threadLocal;
};
private readonly DecoratorExpressionInterceptorData data;

0 comments on commit 4b9db73

Please sign in to comment.